From June 30, 2016 to April 11, 2019, transgender personnel in the United States military were allowed to serve in their preferred gender upon completing transition. From January 1, 2018 to April 11, 2019, transgender individuals could enlist in the United States military under the condition of being stable for 18 months in their preferred or biological gender. Since April 12, 2019, Directive-type Memorandum-19-004 took effect and transgender personnel in the United States military are not allowed to serve or enlist in the United States military, except if they serve in their birth gender, had been grandfathered in prior to April 12, 2019, or were given a waiver. So, I'm afraid your information is no longer true.
Noncitizen service members, like other noncitizens, can be deported under the Illegal Immigration Reform and Immigrant Responsibility Act, which said immigrants could be deported for wider variety of crimes, including nonviolent offenses. Noncitizens who serve in the military are able to apply for legal status after about six months and eventually can apply for citizenship but it is not guaranteed. And since it now considered a felony to cross the border illegally, no longer a misdemeanor, any illegal immigrant, whether they served or not, can still be deported by ICE. In fact, ICE has occasionally and erroneously deported legal citizens that they suspected had documented their papers. This includes former military personnel.