He pointed to a badge, but it allegedly belonged to an operations manager who reported it missing in October.
Police say Mr Singh arrived on a flight from Los Angeles to O’Hare International Airport on 19 October.
He reportedly found the staff badge in the airport and was “scared to go home due to Covid”, Assistant State Attorney Kathleen Hagerty said, according to the Chicago Tribune.
He managed to live on handouts from other passengers, she told the judge in the case.
Cook County Judge Susana Ortiz expressed surprise at the circumstances of the case.
“So if I understand you correctly, you’re telling me that an unauthorised, non-employee individual was allegedly living within a secure part of the O’Hare airport terminal from 19 October 2020 to 16 January 2021, and was not detected? I want to understand you correctly,” she said to the prosecutor who outlined the allegations on Sunday.
Mr Singh lives in a suburb of Los Angeles and does not have a criminal background, according to Assistant Public Defender Courtney Smallwood. It is not clear why he was in Chicago.
He has been charged with felony criminal trespass to a restricted area of an airport and misdemeanour theft. He has been barred from entering the airport if he is able to post the $1,000 (£738) for bail.
“The court finds these facts and circumstances quite shocking for the alleged period of time that this occurred,” Judge Ortiz said.
“Based upon the need for airports to be absolutely secure so that people feel safe to travel, I do find those alleged actions do make him a danger to the community.”
The Chicago Department of Aviation, which oversees the city’s airports, said in a statement: “While this incident remains under investigation, we have been able to determine that this gentleman did not pose a security risk to the airport or to the travelling public.”