This expression describes a situation in which someone is doing something risky or dangerous that could have unpleasant or serious consequences.
If you are walking on ice that is too thin to hold your weight, you run the risk of breaking the ice. It may hold for a while but, unless you are extremely lucky, sooner or later it will break and you will fall into the freezing cold water.
In the same way, the phrase “on thin ice” is used to describe circumstances where something could easily go wrong, particularly when someone is engaging in behavior that will cause them trouble. For example if a child is being disrespectful, their parents or teacher might tell them they are “on thin ice”. Or if someone is late to work too often, or doesn’t pay their rent, they would soon be “on thin ice” with their boss or landlord and face negative consequences. Either way, taken literally or figuratively, “on thin ice” is a risky place to be.