The biggest protection for interplanetary craft is the sheer transmission power needed to get a clear message to them across such vast distances. You can't just set up a ham radio antenna in your backyard and shoot a message to Voyager! The Deep Space Network uses massive dish antennas for uplink -- the dishes are 26, 34, and 70 meters (for various purposes), sited in California, Spain, and Australia.
So hijacking a space probe is outside the reach of individual pranksters, but possibly within the capabilities of a competing nation with its own massive transmission dishes. Most notably, the USA and USSR would, at one point, have had reason to want to mess with each other. Historically, that hasn't happened, though. Partly, this is because it was the Cold War, and actively sabotaging a rival power's space assets would be a good way to turn up the heat (and it would be nigh impossible to send such a powerful radio transmission into space without being overheard doing it).
But everyone was aware of that risk, so the Cold War quickly drove everyone to encrypt and secure communication channels, and in the cases where they didn't, it did come back to haunt them. For example, it was a huge embarrassment for the USSR when British researchers identified the Luna-9 probe's signals as a common radiofax format and got their moon photos printed in newspapers before the USSR had the chance. (The Soviet scientists had intended to analyze the photos and publicize them along with their findings in a few weeks, so the Brits were able to scoop them.)
Today, we rather expect that the world is listening, so spacecraft generally all use encryption systems that allow them relative certainty that messages are originating from the proper ground station. For example, NASA's 2020 FAQ about SMD (Science Mission Directive) uplink encryption explains that there's an exception from their high encryption standard for craft intended to operate over 2 million km away from Earth, but
Even missions falling under these exceptions should consider whether adding encryption would be prudent. While ensuring command integrity may not include encryption, there should, at a minimum, be a level of authentication included.
So you shouldn't be able to just send a command to Perseverance on Mars even if you had a big transmitter and knew what the instruction format was. Of course, rules are not always followed, hackers could figure out an encryption routine, and so on. COMSEC (communications security) is a complex field that is constantly changing and does not typically break down to a straightforward yes or no.
A little closer to home, though, the story is a bit different. Hacking satellites in low-earth orbits or geostationary orbits is a real concern. In fact the organizers of the DEFCON hacker convention launched a satellite to LEO in June 2023 as the target for their Hack-A-Sat contest during the convention in August. I'm not aware of any actual satellites being hacked by "griefers", though governmental agencies have -- but on the other hand, we wouldn't necessarily know that it was hacking rather than a hardware failure if a satellite suddenly went dead, and a hack might not be an attack on the satellite's function if they just wanted to figure out the decryption keys and read its mail.