Under CA law, the owner a a single-family dwelling, or a multifamily dwelling not exceeding 4 units, must inform any potential tenant in writing of a pending foreclosure. If after notice is given, the tenant agrees to enter the lease they would be responsible for any security deposit the owner may require.
You can file a motion asking the court to stay the writ of possession pending the quiet title action. However, based on the information you provided it sounds like you already asked the court for a stay and it was denied. Did you file a response in the unlawful detainer action? You could potentially appeal the unlawful detainer decision and request a stay of the writ pending a decision on the appeal. However, you should have an attorney review the details of your case as there are a few issues...
Below is a link to the website with instructions on how to request a replacement green card.
Many attorneys will charge a flat fee for their immigration services, however, attorney's fees can vary based on a number of factors. Below is a link to the CA Bar Association as well as a link to the US Department of Homeland Security for information regarding the various forms and process to obtain a green card.
Based on your facts above, the home has not been sold at a foreclosure sale yet and you still have title to the property. In that case, the tenant is still required to pay rent to you. Once, or if, the home is sole at a trustee's sale then the tenant is no longer required to pay rent to you because you are no longer the owner. Therefore, you could send the tenant a Three Day Notice to Pay or Quit.
Regarding the security deposit, you should review the terms of the rental agreement....
There are a few questions that need to be answered such as, did you enter the US legally and has your current visa expired? You should speak with an attorney to get all the necessary information so that they can properly advise you.
It sounds like you're referring to "in camera" review which means that the court will review the information in chambers and outside of the presence of a jury or open court. Whether or not the court will reach a favorable decision after reviewing the information is a separate issue.