Tanks were originally just for busting through lines and then the tankers would dismount and fight.
That tactic was begrudgingly abandoned due to the efforts of the originator of the blitzkrieg, a British tanker named John Frederick Charles "Boney" Fuller. He fought hard to abandon the cavalry esque tank warfare doctrine in favor of tanks pushing with infantry following to secure land in their wake behind other mounted forces. The German Blitz was a direct product of the war theory writings of Fuller that was religiously studied by Heinz Guderian and actually implemented to devastating effect.
Following a tank to protect against an entrenched enemy was slow and left too many troops open to fire from off axis angles of attack. A single machine gun entrenchment, it was effective in preserving forces but, if there were adjacent emplacements, the troops were easy targets. It was better to pound emplacements with artillery and planes, then follow up with tanks, and finally troops to mop up what remained.
Modern doctrine is to bomb, send in armor, then armored vehicles with troops to clear and hold with air support to deal with harder targets. That is variable based on the exact enemy and terrain, but that is the basic formula.
So the tank leading troops was a relic of earlier doctrine and invalidated by advancements in war theory made possible by technological advancements in both aviation and artillery.