Recently in a session, I almost caused our party to fight a lich at level 5. For D&D 5e, a lich has a CR of 21. There were a few clues to his strength that I missed, such as being locked in a room intentionally with a relatively powerful spell we managed to dispel, that he threatened to fill the room with gas (lich power), and that he was creating spell scrolls.
My party and I are relatively new to this. My DM told us he was basically an undead guy, but I had fought them before and wasn't much impressed. We later found out he was a lich after the session and my DM told us the various ways in which he would've fled while almost killing us all in the process. This was quite a shock and my party was a little concerned with my aggressiveness towards this random NPC that told us to leave rather than outright attacking us.
What are some ways my PC can find out how powerful an NPC is without prior knowledge of his CR and without the DM telling us explicitly what the creature is? I intentionally don't read the Monster Manual so that my character will be as clueless as I am in real life.
I generalized what the DM had described the Lich as because I felt it wasn't important, and I still feel that way because this is a player issue, not a DM issue. However, since a lot of you are commenting on the description, I feel I should clear the air a bit. Here is the context as best I can remember it.
We dispelled a magical seal on a door and busted into a laboratory with ancient tombs and alchemical stuff everywhere. There was a man at the end of a long room and he took no notice of our entrance, though he knew we were there. He was busy reading or writing something, it was hard to see. My character has a strong affinity for books, the arcane, and especially forbidden knowledge. I ran up to him and upon getting closer, noticed that his flesh was falling off of his body in a very undead sort of way. "Leave now or I'll flood this entire room with gas", said the man in an intimidating tone (effort #1 of my DM to discourage me as most characters are not role-played this way). Knowing nothing of Liches or undead that can speak in general, I, the player, kept forward, asking questions about who he was and what he was doing. As I came closer I noticed that he was writing a scroll of invisibility. I also then noticed, as he turned to face me, that his eyes were white and had a dead look in them (undead clue #2). I, the player, assumed some quick get-away with the scroll and perhaps some lever I could not see that would deploy the gas. I almost cast a spell on him to keep him there, but decided to ask him more questions, testing the limits of his patience.
It was at this point he told us he was a lich and he urged us to leave him be. Then we made some deals, we left, and the session ended. I do not feel my DM was inadequate in this matter, so much as I did not push him to find out who or what this man was initially and that we as a group play in a way that forces us to deal with consequences. He is not there as a safety net, and we as a group like it that way.
There is no absolute way to tell, no spell that says "he's level 10/10 HD." You have to go with context clues and observation instead. That leads us to a two-part answer.
DM Description and Observation
Observe more closely and the DM should be more forthcoming with details. In many cases, higher level NPCs/monsters look different - think World of Warcraft, you can tell a high level person because of their crazy pimp looking gear and purple energy coming off them and stuff. Maybe he has ioun stones whizzing about his head, etc. Judicious use of detect magic, detect evil, etc. can tell you strength of auras. A DM should also think through setting up context clues per How can DMs effectively telegraph specific dangers in D&D? - like maybe someone powerful comes to mess with him and gets disintegrated while he's chatting amiably with the PCs.
Many high level characters are obvious - a gnome in a robe of the archmagi riding a dinosaur with all kinds of magical protection glimmering around him is obviously bad news. If all your gear is platinum and adamantite it means you're bad ass enough to keep a hold of it from random bandits and/or adventurers. Your DM should be conveying this detail, as long as you pause to take a look.
In some cases (monsters, undead) skill use may let you get a better read on what it is you're facing. In 3.X this was sadly routine (I will roll and you will tell me exactly what this is), in 5e this isn't as guaranteed a method of knowing exactly what's up and there's more DM discretion, but at least asking for a roll and getting hints might help.
It definitely sounds like your DM needs to be thinking through this more and giving more context. "Hey this dead guy looks a lot like that statue of Archmage Xulibraz back at the Acadamae..."
In some cases, a high level person isn't going to look/detect different from a low level person. This should be more rare unless your DM is a dink, though there are exceptions. A high level monk in rags looks like anyone else and a king might have super pimp gear despite being level 1 just because of daddy's money. Now, if you see the monk fight it should be like watching Jet Li and you should get the clear impression he could snap your neck and isn't some random yokel. But this is where the onus shifts to you. If you decide to just roll up on someone without knowing much about them, there's a good chance you're going to get owned one day. You have to be smart.
Observe folks. Ideally, use time prior to the actual encounter. If you know about them way ahead of time then there's divination spells or sage research or "asking around on the street." See if you can observe them fight someone or cast a spell or use a skill to where you would see "holy crap they are about 500% better at that than I am." Have a backup plan. If you just kick down doors and attack people, 1 in 10 times you're going to bite off more than you can chew and you'll need a fallback. That floating thing could be a beholder or a gas spore. That undead could be a zombie or a lich. Knowing that there is that range of foes, it's up to you to decide whether you want to be all reckless and maybe die one day or whether you want to be super cautious with everything or where you want to fall in between - just like real life.
You have just learned a valuable lesson, and learned it without dying! Congratulations. The world is dangerous and it's not always neatly labeled or level appropriate. Let this inspire you to think about how to suss out your foes both from afar and when in direct contact with them. It'll keep you alive more than a fistful of plusses.