It isn't the SFMTA themselves -- they contract with an operation called NextBus. NextBus installs GPS tracking devices on the transit vehicles, which radio their route, direction, and position back to a central system that then computes ETAs for all the stops on the route. That info is then exposed via a website, an SMS gateway, custom digital signs at the stops themselves, and via the API. It's incredibly useful to have, and there are half a dozen apps out for iOS and Android that show this info to you on the go.