I wouldn't hesitate to land at a military installation. As stated above, ATC should have coordinated with the installation and you'll have a personal escort upon arrival. I can't see the FAA even slapping someone on the wrist for doing so and might be used in training others. Those hesitating to call an emergency are often who we hear about in the local news, and not in a good way. Good controllers will declare an emergency for a pilot when they sense something is wrong, helping take some decision making load off a pilot in distress so they can focus on flying their plane, e.g. "level your wings and keep flying present heading", "make a slow right turn and I'll tell you when to stop", etc.
You’re naive.
It won’t be the FAA that “slaps” you if you land at a place where you’re not authorized because of the security level of the installation.
It will be the security forces pointing their rifles at you while they command you to get on the ground.
Failure to comply with that instruction will not go well.
Those rifles are loaded. Those forces are authorized to use lethal force.
Now, not all installations operate at that level of security, however, some do.
If you were wise enough to comply with their instructions, then at the very least, you’re going to spend some very uncomfortable time while you and they have a talk.
This isn’t TV, this isn’t the movies, this is real life.
I had a sailor who stepped out out of his working space into the hanger bay when weapons were being moved.
Despite announcements, and despite directions from the Marine Security forces aboard the ship to return to his space, he wanted to “see what was going on”.
While he was mouthing off to the marine in front of him, a marine came up behind him, put a rifle butt to the back of his neck, and had him on the ground in a split second.
Cuffed. Hauled off. Thrown in the brig.
This was a sailor assigned to the same ship, mind you.
So, as a new pilot, let me caution you, that not all “military installations“ are the same. If you have a problem, talk to the tower, if they clear you to land, that’s great.
If they don’t answer, or they don’t clear you, then you are about to have “a problem“.
One example of this is P-56 in Washington DC.
I don’t care what’s wrong with your airplane, you are better off crashing, than approaching that prohibited area.