What is the purpose of this transistor in this schematic?
It is an automatic switch to turn the LED off during charging (and allow most of the charge current to flow into the battery).
When the mains is connected and the cathodes of the 1N4007s go negative, the base of the BJT is pulled to approximately 0V so the LED turns off, and most of the current flows into the battery, except for the current through the 520\$\Omega\$ resistor (kind of an odd value, are you sure?).