It is (most likely) an old Switch Loop
Switches are confusing until you have that "aha!" moment (which actually took me quite a while).
A switched fixture typically includes:
- Grounds everywhere - connect them together, no reason to disconnect when removing the switch, so they are still connected.
- Hot from the panel to the switch - that is one of the black wires.
- Switched Hot from the switch to the fixture - that is the other black wire.
- Neutrals - one from the panel to the switch and one from the switch to the fixture, so they are connected together.
However, older switches (and current switches that are "just switches" and not dimmers, smart switches, lighted switches, etc.) do not actually use the neutral. Sometimes you will not even find the neutral inside the switch box because it doesn't actually need to be there. Code now requires a neutral to allow for dimmers, smart switches, lighted switches, etc. so the configuration you found - neutral from fixture and neutral from panel connected together - is perfectly normal. If you need neutral for your new switch, pigtail it to the existing neutrals.
So why aren't the blacks connected? Because that would complete the circuit. If a fixture is still in place then it would always be on. The gap between the two blacks is equivalent to an "off" switch.
As others (especially Harper) often point out, a black switched hot is a convenience (NM cable is normally black + white + ground) but is confusing, so labeling it by putting red electrical tape on both ends (in the switch box and at the fixture) avoids confusion. But most of the time it is just another confusing black wire.
The one important thing to figure out is "which black is hot and which one is switched hot". That is actually easy: Using a non-contact tester with the circuit breaker ON, the "hot" black will be live and the "switched hot" going to the fixture will not be live.