How does this 1 wire to 2 fixtures & 2 switches work? Is it safe?
It looks like they spliced in a switch loop in the middle of the run. The bottom bunble will end up in a switch that controls the light in one of the rooms.

However the colors are not correctly matched. and the ground to the switch is missing.

The proper way to wire it is first of all in a junction box.

Then the whites (neutrals) should be pigtailed together. So should the grounds.

Then the black should be connected to the power source and red to the light being switched.

At the switch itself you cap of the white, connect the ground to the ground screw and connect the black and red to be switched.