You can't get a T-Mobile version of the OS installed. The AT&T variant of the phone only will run AT&T versions of the OS.
You can install some T-Mobile apps from Google Play, though. But, your pre-installed AT&T stuff will continue to live there.
If feasible I would suggest buying a T-mobile branded device as the S5 lacks the hardware to support a large portion of the T-mobile network. If you want to stick with Samsung the S9 would be a great buy as it even supports Band 71. If it is not in the budget the S7 would be a great phone as well.