Yes and no, theres a time and place for everything. Its generally harmless in most situations, but you definitely need to be aware of body language and context as well
Your own demeanour as well will drastically affect how someone receives your compliment. Looking unwashed and smelling like BO or having a tshirt that could be really tasteless to some people might make the “your hair looks beautiful” comment to a stranger sound far creepier than you intended. Like a tshirt that says you love a certain serial killer that was notorious for keeping hair trophies of his victims, thats a no no
Human communication is incredible, there are just a billion variables that’ll affect how messages are handled and its a lifelong process of learning and adapting how to properly interact with the world around us