How did aircraft in WW2 navigate to the carrier after their mission? I was thinking of something like a beacon installed in the carrier but wouldn't it reveal the location of the carrier itself?
You are correct. US carriers did indeed have a homing beacon that enabled aircraft to find them.
The carrier transmitting units were called YE or YG, and the receiving units in the planes were designated ZB, and called "Zeebies". The transmitters consisted of rotating "superfrequency" beacons that broadcast different morse letters in different directions that could be decoded by the ZB units, but sounded like static to ordinary listeners. They were installed on all US carriers in WW2.
Here is an excellent summary of the system and its history. More information can be found here and here, and History SE already has a question about it.
The British also had a similar system, installed on a carrier in 1936 and used through the war.
Sources also indicate that the Japanese employed a radio homing system (Hirohito's War by Francis Pike), but I have been unable to locate any details.
American carriers were fitted with a line-of-sight radio homing system, but Japanese aviators were probably limited to old-fashioned dead reckoning, since Japan was less advanced in electronics than the U.S.