The 5th amendment protects you from self-incrimination. If by possessing a firearm you are in violation of the law you cannot be compelled by law to reveal this information. If the police discover you have a gun in violation of the law you can be arrested and prosecuted for that offense. They cannot additionally prosecute you for not telling them about a gun.
I thought there was a supreme court case about this specific situation, but the closest I can find for now is Haynes v. United States. The 7-1 majority held that people prohibited from possessing firearms cannot be compelled to register their firearms that they are possessing illegally.
They are stopped by the police and asked this question. They answer truthfully.
Then they can be arrested and prosecuted for the illegal possession of the gun.
How does this square with the right not to self-incriminate? Or is asking the question considered to be a search?
Police can generally ask whatever they want. If you choose to waive your 5th amendment rights, that's your mistake.
Can the state prosecute this person for carrying the illegal weapon?
The state can generally prosecute crimes it knows about. So yes, in this case they can.
Suppose that next to the weapon a stash of illegal drugs is discovered, which was only found due to the action taken to secure the weapon. Can the state prosecute for that?
The state can generally prosecute additional crimes it uncovers during investigations or other lawful actions. So yes, this can be prosecuted.