What is the purpose of the hole in the top of an LD1117V33?
While the TO-220 package of the LD1117 can certainly be lead-formed to place the heat sink tab (the metal part with the hole) flat on a circuit board, another way of using it is to bolt a heat-sink onto the metal tab while leaving the part standing upright:


(Source: Adafruit)

Similarly, in many applications the through-holes for the TO-220 part will be close to the edge of the board, so that the tab can be directly bolted to an outer metal casing for the device. Appropriate insulation in the form of a nylon sleeve and mica washer electrically isolates the metal of the heat-sink from the metal casing, while allowing heat transfer.