Can't remove ignition key

Recently I could not remove the ignition key on my 2007 Pontiac G6 after parking and turning off the ignition. Co-worker suggestions for a fix indicate that (1) little shavings from the key have come off over time in the ignition, and it was suggested that I use WD-40 to lubricate the ignition, or (2) the car was not fully in park and I simply have to make sure the car is in park. The curious thing is that the key did eventually release while I was locking and unlocking the doors using the remote keyless entry and the problem has not yet repeated itself. I am not sure if lubricant in modern ignitions is safe, and I tried repeatedly starting and restarting the car and moving the gear shift and this did not help. Does anyone have a suggestion for a diagnosis and solution?

Was the switch in the OFF position fully when the problem occurred?

You might check the battery to see if it has a full charge. On newer GM vehicles the key cannot be removed if the battery is weak/dead

This happened to my wife one time. The solution…Put the car in PARK. Yes, she left it on D. Everything turned off but the key will not come out. She called me and when I got there, I laughed and then put the car in PARK. Key came out.

WD-40 is not recommended for locks because it causes things to gum up over time. Graphite is preferred instead.

This can be caused by a variety of problems. One time I got my front wheel stuck up hard against the curb, so I couldn’t wiggle the steering wheel, and that caused it to be difficult to remove the key. The tension in the steering wheel/key interlock caused it to stick I guess.

I do have a key maintenance routine, maybe that will help. First, remove anything not absolutely necessary from your key ring. The weight of the keys, especially as they swing back and forth as you stop and go, wears the ignition switch mechanism. 2nd, wash your keys every once in a while. Like every 2 or 3 months. I put mine in the dishwasher, but its probably better just to wash them by hand and dry thoroughly. 3rd, whenever I go golfing or to the library I take one of those little stubby pencils, they seem to have a nice soft lead, and I run the pencil lead along the key surfaces and grooves. This makes it easier to insert and remove the key.