It's because the Panama canal was constructed by connecting several previously naturally existing (fresh) waterways and a big lake, to the ocean on both side. The whole point of the locks is to raise and lower the ships to the higher elevation at which the lake sits. Water runs downhill, it starts as rain, then to rivers and lakes, then the ocean. So in this case rain and natural watershed basins drain into the lake and then the locks release it slowly down to progressively fill each lock, until the water is at the ocean, at which point it can't efficiently be separated from the seawater, so it just becomes part of the ocean.
The people there drink the fresh water and chose to settle in that area originally because ot was there. We then built a canal after. It wasn't like we built the Panama canal as a water source for the local folks.