Whether grounding the tab or connecting it to heatsink is safe depends on your circuit.
You can largely decide if is is safe in the same way that you'd decide in any other case whether connecting two or more chosen points together were safe.
The tabs offer you an interconnection option - you have to decide whether to accept their offer. If the offer is to be declined you will need some insulating mounting "hardware" such as Steven has shown. Make sure you are doing what you think you are doing when you use any such systems. In systems above a few Watts of power a TO220 device can fry in seconds if heatsinking is almost but not quite connected.
Some ICs offer isolated tab versions with the tab encased in plastic with a suitably high voltage rating. Connection then can be made via the middle lead.
eg If the ICs concerned were all 78xx family regulators with the tabs all at ground potential you may decide that grounding the heatsink and connecting all tabs electrically to it was acceptable. But if eg you had an LM7805 (+5V regulator) and an LM7912 (-12V regulator) you would find that the LM7805 tab was at ground but that the LM7912 tab was at -Vin. Connecting both these points together electrically via the heatsink may produce some interesting magic smoke but would be liable to spoil your negative supply source's day (as -Vin and ground would be connected, and ground usually beats rock, paper, water and -Vin.) In this case you would want to electrically isolate one or both of the tabs from the heatsink. Having the heatsink at electrical ground is often an OK choice. Having the heatsink at - Vin is usually a really really really bad idea. If the heatsink MUST be connected to something electrically then connecting it to ground is usually the only safe choice.
Sometimes you may decide to not connect a grounded tab to a grounded heatsink and to use insulating hardware just as you would if the tab was not at ground. For example, you may expect a ground loop to occur in some systems if the tab was grounded both to the heatsink and also within the circuitry connected to it. In audio equipment earth loops are to be avoided like the plague and, if you care about low level analog signals (such as ADC inputs from wherever) then ground loops will be unwelcome.