Does the flight always switch to TRACON on a go-around in class B airspace?
It depends. As a rule oh thumb, a missed approach will be handed over to approach (TRACON) to get a new approach clearance. Some places have local rules that allow approach to delegate this responsibility to the tower when it makes sense, which means the aircraft can then stay on the tower frequency for the new approach. This would normally require a few things, such as appropriate equipment being available in the tower (radar) and having a tower controller that is actually rated to be allowed to perform approach control.
In any case, when a go around is initiated, the tower will immediately call approach and coordinate what to do. One of the results of this coordination is the &quot;heading and altitude&quot; you have heard the tower give to some flights. Typically, approach will request to get the flight at a specific heading and altitude, and the tower will give those instructions before handing over the flight. Some airports will have very specific local regulations about which steps to follow, others allow the controllers to come up with a solution that fits the specific situation.