What is “closeted”?
Although closet now means "wardrobe" in American English, it originally meant a small private room for study or prayer. Now that we know this meaning of the term, the metaphor in the closet makes perfect sense for a person hiding their identity. Because the closet plays a dual role, being a source of both comfort and fear.
There are several reasons why LGBTQIA+ individuals may decide to stay in the closet. In most cases, these are the following:
Still questioning one’s identity
Many people who are still exploring their sexuality or gender have not come out to themselves yet. Due to this reason, they cannot come out to others. Some of these individuals might already have self-identified as gay, lesbian, transgender, etc., but have not yet found the proper label for themselves.
Fear of not being accepted
Fear of being rejected by friends, family, coworkers is is one of the most common reasons for staying in the closet. It affects particularly young LGBTQIA+ people because they risk losing financial support from their parents.
Unsafety
If a person belongs to a religion that regards same sex-relationships as a sin, lives in a country where being LGBTQIA+ is illegal or punishable in some way, it is totally understandable why they choose not to reveal their sexual orientation or gender identity to anyone. For example, it is extremely risky to come out as gay or trans in Afghanistan and many other Islamic countries. Believe it or not, if an LGBTQIA+ reveals themselves to their family in such countries, they could beat them up or even kill them, not to mention if they come out publicly.
However, even in civilized countries, there are still homophobic/transphobic/queerphobic families and hostile school and/or working environments, as sad as it may sound. Often, unless such people are able to move out from their parents’ house, find a job in an LGBTQIA+ friendly company, and/or emigrate to another country, it is much safer for them to stay in the closet.
Denial of and/or phobia towards one’s own gender/sexual identity
An individual being unable or unwilling to acknowledge their identity because it "cannot be true" in their subconscious, they know that it is true is called internalized homophobia/biphobia/transphobia/queerphobia. Unfortunately, it often happens when a person is subject to negative perceptions of LGBTQIA+ and intolerance towards them in society.
So, such an individual starts believing those ideas and turns them inward. It puts their mental and physical health at risk because this self-hatred may result in chronic stress, insomnia, anxiety, depression, substance abuse, suicide attempts.
Closeted pride flag
There are several flags for closeted people depending on their sexual orientation/gender identity. The most popular closeted flag for gays and lesbians was created by the user Touchcreator. Essentially, it is a pastel version of the rainbow flag with a brown closed-door symbol in the center:

There is one more version of the flag for closeted gay people created by the Tumblr user, decentmonster:

The flag is light blue with a shrimp on it. The creator of this closeted pride flag explains this design in the following way: the authentic shrimp color is invisible to people, and closeted individuals are proud of themselves even though nobody knows it.
The Transcloseted flag, made by Tivian:

The closeted trans flag represents a narrow version of the original trans pride flag in the middle with two vertical black stripes on the left and right:

History of the term and interesting facts
Some very famous people, like singer Ricky Martin, top model Cara Delevingne, actress Kristen Stewart, were told to be in that glass closet, otherwise, they would never have made it in the entertainment industry. And they did stay there for years. At some point though they stopped caring what ignorant and hostile people say and finally came out. And their fans could not be happier that they did!
However, according to a 2019 study conducted by the Yale Public School of Health, more than 80% of LGBTQIA+ people worldwide prefer not to reveal their gender identity and/or sexual orientation. In the USA, only 4% of gays and lesbians and 26% of bisexuals have not come out to at least one of the people in their lives like family members or friends.
Fortunately, as the acceptance of LGBTQIA+ individuals in society grows, there is less and less need for non-binary and/or non-straight people to stay in the closet. Multiple studies show that it is very beneficial for a person’s mental and physical health to be able to live their best lives authentically, without having to hide in the closet.