Why does the transistor work with collector and emitter swapped?
The transistor is in reverse active mode. The collector acts as the emitter and the emitter as the collector. This is possible because NPN reversed is still NPN.

The performance is worse than in forward active mode, because emitter and collector usually have different doping levels and a different structure. Therefore this mode of operation is not very useful.

Another problem with this circuit is that one has to be careful not to exceed the maximum reverse voltage of the base-emitter junction.