How does a cryptocurrency stay pegged to USD?

There is only one true way of doing that. It is by controlling the supply and demand. 

Lets say a crypto claims to be a stable coin pegged to the USD. Some investors now have brought 10 million of those tokens and hence its market capital is now 10 million USD. 

Now, some investors want to sell it and when he sells it, the main company that issued the tokens buys the tokens back at the same price of 1$ per token. 

Now, some more investors want to buy it. When these new people put buy orders on the market, the company that issues the token creates more of these tokens to deal with the extra demand. 

If the token company uses some funds due to operational costs, they will burn the tokens backing the used up dollars that they no longer hold. This is how stable coins control supply and demand and keep a coin price at a specified rate.