Human negative G limits for pushing the nose down are about 3G, vs. maybe 9G positive G limit for pulling the nose up (or downward while inverted), very roughly, and as other answers explain, negative Gs right before positive Gs could be even worse. Airframe design limits for the F/A-18 are about -3 .. +7.5 G, per @max's answer.
This is how real fighter pilots fly when following terrain, even when it's less dramatic than a mountain peak. When cresting a smaller ridge, you might not roll all the way inverted, but rolling to 90 degrees as you approach the crest removes the vertical component of lift. And rolling past lets you pull some Gs to get the nose down while turning some. (Or just go fully inverted if you want to keep your heading while dropping the nose by any significant angle.)
C.W. "Mover" Lemoine flew the F/A-18 for the US navy (and other jets for the USAF). On his youtube channel, he posted cockpit video from his first low-level training flight (looking forward over his shoulder), adding voiceover to talk through what was going on and why.
[4:21] ... [my wingman was] very aggressive in doing the ridge-crossing and stuff which you just saw. Instead of bunting, instead of pushing negative G, you roll to get the positive G on the aircraft so you're not pushing over every time you cross a ridge.
On another ridge, at 6:13, he rolls all the way inverted to pull the nose down after crossing the ridge to see how much drop off there actually is. That one didn't involve much of a change of heading, unlike some of the intentional turns at ridges in the training flight (which is another reason not to roll fully inverted).
This was his first low-level training flight doing stuff like this close to terrain. He says at the start that he stayed a bit high while getting comfortable with the whole thing. At 17:52, he rolls to about 120 or 135 degrees: getting to about 90 before reaching a ridge, continuing the roll a bit more after he can see past it. And he's low enough to see details on trees before cresting the ridge.
If staying tight to the terrain over one specific big crest was critical to a real mission, you likely would roll inverted before the crest. (Unless it was a really wide round curved hilltop, not a ridge at all. If pushing the nose over to follow the curve would only leave the pilot feeling between 0 and 1 G, they might stay upright.)
I haven't seen Top Gun: Maverick yet, but if they only roll inverted at the crest, after pushing the nose down to horizontal, that's probably a movie mistake unless that part happened gradually. Like a shallow curve and then a steep drop.
I'd guess that if you'd scoped out the terrain for a specific ridge and practiced in a simulator, you could be much more aggressive. But if in real life you're just shooting footage for a movie, you're not going to risk your life more than usual. So it makes sense that what you see in the movie is rolling and pulling down at the crest of the ridge, not much before. Assuming that shot was 100% practical, and actually done close to terrain, not a separate shot of a jet composited onto a shot following terrain.