Roll a d20
The quick-and-easy solution I've found is to roll a d20 (either with WIS/INT modifiers or without). If I get 1-10, the character doesn't know, or doesn't think of it, and if I get 11-20, the character does.
This IMO removes the metagaming aspect of knowledge, because if (and what) they know isn't necessarily arbitrary/binary (see below). I think of this as rolling to determine part of a character's backstory, similar to how you can roll for certain things when creating a character. I would note that whether or not they should roll (and potential bonuses, detriments and DC's relating to it) should be directly related to/affected by how well acquainted the PC is with the situation. For example: a barbarian who has had little experience with magic, might have a higher DC or a -2 to the roll, or some similar difficulty detecting magical traps. A wizard who is well versed in magic, (and potentially magical traps,) might have a lower DC or a +2 to the roll. If they know nothing about the situation, they shouldn't roll. A character that doesn't believe in magic, or doesn't know it exists, (for some reason,) would neither know nor care to check for a magic trap.
I would also vary the level of success/failure with the value of the roll. For instance - if we may use the example of a trapped hallway - if the player rolls a 9, they may suspect a creature may be hiding down a dark hallway, and decide to proceed cautiously, though they wouldn't be expecting the trap(s). If they roll a 16, they might check for traps, but not know the number or nature of the traps (magic vs. mundane, whether it's a pit or a fireball, etc.). This would likely not leave them completely helpless, though they may be better prepared for one kind of trap vs. the other.
Uses in combat
This applies for fighting a monster as well. Certain features of the monster may indicate potential weaknesses/resistances. For instance, a water elemental is probably not going to be very hurt by fire. I say that with no reference to the Monster Manual. I - and almost certainly all the PC's - have seen what happens when fire meets water. I made that assumption based on logic and experience. There's no reason the characters shouldn't be able to as well. (Note that I can tell you almost nothing about elementals off the top of my head, so this logic could work for almost anyone.) Similarly, a well-armored foe may not be hurt as much by certain kinds of weapons.
If the player doesn't deduce the enemy's strengths and weaknesses, then they can't automatically play around it. If the enemy has a weakness to the player's attack of choice, then they get use the enemy's weakness. Alternatively, if the enemy is immune to the player's attack of choice, then they'd be out of luck. IMO, the roll should only directly affect the first response. The character can act on "new" information on subsequent turns, as they'd be expected to.
The exact level of knowledge would vary upon the roll, (and perhaps your discretion,) but the player wouldn't necessarily be ignoring logic for fear of metagaming.
For ability checks, the only thing to add is that you may want to talk to your players directly as GM. If you think they are missing information that they should be able to get, maybe you could hint at it. Alternatively, you could also tell them if they should know about something, and what their character might be aware of. I don't know if this will work with your play-style and/or your group, but it worked with mine.
One thing to always keep in mind: Try to keep things fun! Try to balance what the characters know with the environment. I'm not advising you to not punish poor decision-making, I feel you definitely should to some degree. Just make sure you don't overly punish it either. The game is meant to be enjoyed, and that's harder to do if a character dies because of a poor roll. (I assume you're well aware of this based on the phrasing of your question, but I think it's important enough to restate.)
One way to potentially balance this, as well as clue the characters in to the nature of their situation, is if you have an NPC suffer dire consequences for poor decisions. An NPC death is likely to be less detrimental to the experience of the players, and in some cases it can even greatly enhance a sense of seriousness, urgency or danger of a situation. I know this is harder to do, and will not work for everyone or for every situation, but I have seen it done to great effect. (One time it was done specifically to save a PC from death, thus saving the player's experience and causing the loss of a teammate.)
Roll a d20, and use that to decide if the PC's should actually know/deduce something, and how much info they should have. I personally feel it lessens the meta-gaming feel because it can be made similar to character development, and seems less arbitrary. Note: Only (allow a player to) roll if the character might have some in-game way to know/deduce info.