Things are much more complicated than this, but essentially China as a primary exporter wants to keep the value of it's currency as low as possible since the exporters then benefit on exchange rates.
It also wants stability so it basically pegs the Yuan to the dollar, historically directly and more recently in directly (the Chinese central bank sets more or less of a fixed exchange rate but it does allow it to deviate somewhat these days).
Now to prevent the Chinese economy from being effectively run on and by foreign currency China heavily restricts the ownership and settlement in foreign currency internally. It basically forces the exporters/manufactures to exchange the foreign currency they paid in (usually USD) back to Yuan for any internal use (or alternatively if you want to do business in china you basically have to exchange your currency in Yuan it's the same thing).
It then uses that surplus of foreign currency to buy other assets, primarily dollar bonds such as US treasury bonds which basically brings back all those dollars that came from the US and everywhere else in the world back to the US.
And even this is like very very basic overview of things.
On some level the US economy or at least the dollar economy is basically based on the fact that the dollars used in international trade have to come back to the US.
Basically you buy dollars from the US, you use those dollars to buy something e.g. goods from China then those dollars go straight back to the US in exchange usually for "cheaper" dollar bonds.
The debt economy a side the scheme is when viewed on a global scale is almost like you never actually own a dollar you simply rent it out.