My question is if this reasoning is correct and if thunderstorms are common after a heatwave ends in areas where there is some moisture in the air at the end of the heatwave.
In other words, what exactly happens in the atmosphere when a heatwave needs and would this lead to increased chance of thunderstorms in areas where the air has some moisture?
All these forms are expressions of convective weather, vertical movement of air caused by labilization.
Otoh, heat waves are frequently simply the result of dry and hot air being transported by advection, which is not bound to a local scale alone. For example the Sahara air to central Europe. This air is hot and very dry, and it simply lasts until the weather situation changes and different airmasses come along, e.g. of Atlantic origin. There won't be thunderstorms, then, because there's not enough moisture. Such a weather situation frequently happens on the Canaries (just as an example), it leads to a hot and extremely dry atmosphere until great height, with a cool layer underneath, for example 23°C at sea level, ~30° at 500m ASL with an inversion in between, and 35°C around the summits between 2,000 and 2,500m ASL. This is absolutely stable and not even slightly conducive for the formation of convection or any kind of precipitation (except sand :-/).
tl.dr: No, it is not normal, but it can happen. There is no general rule and it is not the absolute temperature that causes thunderstorms, but differences in temperature and moisture that cause labilization and thus convection.