I have the following voltage regulator circuit (AMS1117 SOT-223):

simulate this circuit – Schematic created using CircuitLab
C1 is ceramic and C2 is tantalum. The 3.3V output is used to power a microcontroller.
When input is 5V, everything works fine. However, when I use 12V on input, the regulator burns immediately (and the microcontroller gets destroyed too).
When I begin with 5V and gradually increase it to 12V, it survives and works fine.
I guess that the problem is that when I connect the input voltage, the C2 is being charged by too high current that destroys the AMS1117.
What can be done to prevent this issue? I never thought about output capacitor having too high capacity or too low ESR. How to properly select it? Or is the problem somewhere else?
I replicated this behavior with multiple AMS1117, but when using TS1117 it does not occur.
