Yesterday when I was replacing the old ceiling light fixture with a new led disc light in the laundry room, I notice the old light was being wired like the above diagram (probably by previous owners). Basically there are 2 pairs of wire coming from 2 end of the electrical box. The neutrals (yellow in the diagram) were twisted together. The black wire (red in the diagram) of the light fixture was wired to the black wire (hot) from the power source and the neutral (white wire) of the light fixture was wired to the black wire on the other end of the box, which I believe is connected to the switch? Can someone please explain to me what kind of wiring is this? and is this legal at all? Thanks. P/S: the diagram was drawn on phone so please excuse me if it's not looking good.
The details of this answer assume you are in North America. If you are elsewhere, you should add that information to your question.
Assuming you are correct in the wiring, then no, it is neither legal nor safe currently, though if the wiring is old enough, it may have been "normal" at the time.
The problem is that the switch is interrupting the neutral wire to the light while the hot wire goes directly to the light. The problem is that if you turn off the switch and go to work on the light without flipping the breaker (a bad idea but some people just depend on the switch), you can get shocked as the red wire to the light is still hot.
It should be very little effort to change the wiring so that the switch interrupts the hot instead. Also, on the white wire coming back from the switch, you should add a wrap of black tape or paint at each end to mark it as (switched) hot.