There are no rules that I know of. It simply happens, and it happens differently with differnt people and in different cases. I just tried pronouncing 'but' in a sentence and found that sometimes I'll leave out the 't' and sometimes give it just a flap with the tip of my tongue, more like a 'd' sound.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.