It is said that Rb is optional. But the photodiode needs bias to work
in that way. How on Earth it will be biased? Maybe due to base-emitter
junction, but how exactly does it work?
Without Rb the diode gets its bias through the Base-Emitter junction. This provides maximum sensitivity because the transistor gets all the photodiode current. But sometimes you don't want maximum sensitivity. Rb shunts small photo currents away from the Base so the transistor won't respond to low light levels.
When the transistor is connected in Emitter Follower mode, as in this circuit, it acts as a buffer which reproduces the voltage on Rb - Vbe. So the voltage across RL becomes proportional to light intensity once the voltage across Rb reaches the threshold set by Vbe (~0.6 V).
What if the Rl resistor would be connected to collector? I tried such
circuit with this photodiode and this transistor.
Unlike Common Collector configuration which has a voltage gain of 1, in Common Emitter configuration the voltage gain is very high (typically ~100 times). So once the voltage across Rb reaches ~0.6 V the output voltage drops rapidly with increasing light level.
I expected Rb voltage to be about 1,2V because of the 12uA current
produced by the diode, but actually it was about 0.7V and the circuit
was extremely unstable - it turns off and on for unexplainable reason.
Rb cannot be 1.2 V because the transistor's Base-Emitter junction draws exponentially increasing current as Vbe rises above ~0.6 V (this is the reason for the high voltage gain in Common Emitter configuration). The circuit didn't turn on for an 'unexplainable' reason, it just became very sensitive to light intensity variations above a threshold level.
This is useful when you want a circuit to turn on and off when the light level goes above or below a certain intensity, for example in a nightlight daylight sensor. However since Vbe is temperature sensitive and ambient light levels may vary, it is more commonly done with a linear light sensor followed by a comparator with adjustable threshold to set the switching point.