Passing USMLE has nothing to do with staying in USA. You can take USMLE Step 1 and Step 2 CK in any of Prometric centers around the world and then you can take Step 2 CS in USA.
The aim behind taking USMLE exams is to be able to do residency in USA. Residency is considered a job and you will be paid $40,000 to $48,000 per year. If you apply for this job (residency) and get it then the hospital will sponsor you (they call it J1 Visa) and you can stay for the entire period of your residency (usually 3 to 5 years).
However, after finishing your residency and perhaps some fellowship after it. you cannot stay in USA if you don't have an immigration status such as Green Card.
Nonetheless, many IMGs have managed to stay in USA despite those hurdles. Like by marrying to a US national or by starting their own business sponsoring themselves or by applying to asylum or by getting a hospital/clinic to sponsor them, ...etc