What's the fourth pin in LD1117-33 for (the thick on the top)?
I can't find a picture of an SOT223, but here is a TO-220 which follows the same principle:
You can see how the tab and the middle pin are one and the same piece of metal.
As others have rightly mentioned, this is for heatsinking purposes, and is often required. It is also used in some packages for high current connections, where you may have the tab as one connection, then 4 or 5 pins together for another connection (such as in >100A MOSFETs).
Right out of the datasheet page 2 :
NOTE: The TAB is connected to the VOUT.
And it is often used as a little heat sink soldered on the PCB
Not only is it usually connected to the middle pin, its typically required for heatsinking.
You're supposed to solder it to a nice big area of copper on your PCB.
You'll also notice on the DPAK that pin-2 is not really a solderable pin, so the only way to connect to that part of the IC is through the tab.
The tab on SOT223 packages is commonly for heatsinking purposes and is most commonly found on devices that get warm, such as linear regulators and various transistors/mosfets etc. If you connect it to a larger copper area on the PCB, heat can flow from the device into the PCB.
It is commonly connected to Vout but not always.
It's connected to the middle pin, Vout. Having Vout on the middle pin and tab instead of GND is kind of pain in the ass when designing your circuit, because placing input and output capacitors around is more difficult and also you can't use part of the ground plane as a heatsink.