How does this BJT transistor work without any connection to its base?
Of course, this is a classic avalanche relaxation oscillator circuit. 

No it is not safe for the transistor, the reverse breakdown of the \$V_{BE}\$ junction will degrade the \$h_{FE}\$, so you should throw the transistor away after performing this parlor trick. 

There are transistors designed for avalanche operation - which can create very fast pulses. I think they're mostly sourced from the former Soviet Union, at least one with a Western brand name. 

It's kind of a fun circuit, most jellybean transistors will work, but you need a relatively high voltage (like 12V). 

I suspect (but don't know for sure) that this won't work at all in a SPICE simulation (with the classic Gummel-Poon model).