I thought I could smell something burning while driving so I pulled over and popped the hood of my car. I was checking my engine when a police officer pulled up. He had me drive over to a parking lot. When we were there I popped my hood and got out to continue checking and he asked for my license. Is that legal? It happened in Illinois.
In most states, if you had said "Am I being detained, or am I free to go?" and the answer is "you are free to go", then you do not have to provide ID. In Illinois it can become more complicated, the Criminal Code of 1961 does not impose a duty for a suspect to identify themselves and cannot be charged of obstructing a police officer for refusing to identify themselves or refusing to provide identification.
In Illinois it is actually legally allowed for police to "demand" an ID, but there is no requirement on your part to provide it, and technically a police officer is only allowed to "demand" it if they have reasonable suspicion that you are committing, have committed, or is about to commit a crime.
So really in Illinois an officer can only "demand" your ID if they have suspicion of a crime (past, current, or future) and you are not ever legally obligated to provide it, nor can you be charged for not providing it. If the officer said "can I see your ID"? and you provided it, then that is legal since you voluntarily responded to a request (not a demand).
It is not obvious from the description. 725 ILCS 5/107-14 is the relevant law. When legally stopped, the officer
may demand the name and address of the person and an explanation of his actions. Such detention and temporary questioning will be conducted in the vicinity of where the person was stopped.
This is stronger than "may request", and is more likely than not to be interpreted as obligatory. You note that the law provides an obligation to give information, not produce a document.
It is not clear that the stop is legal. The requirement is that
after having identified himself as a peace officer, may stop any person in a public place for a reasonable period of time when the officer reasonably infers from the circumstances that the person is committing, is about to commit or has committed an offense
This is the Terry stop rule on brief public detentions. On the face of it, this is not a traffic stop (you were already stopped: but you didn't say exactly where, which is an important detail). If you just stopped in the road to check your engine, that would be highly irregular and probably itself illegal, so demanding ID would probably be legal. This is a fact-intensive distinction, whether there was or was not a "reasonable suspicion". A vague "feeling that it just didn't seem right" is not reasonable. A lot of other articulable reasons are reasonable.