There is a solenoid under your carbeurator. Check to see if the connector is loose or was accidentally pulled off.
Should be a normally closed condition when off to keep from wasting power.
You should be able to put your hand on it, and feel it click to open with the key turned on. Switch the key off and on a few times. If you feel/hear it click, your key switch is fine. If not you can also pull the connector off the keyswitch and clean and tighten the contacts.
Most likely the solenoid needs to be replaced. Depending on your model, might be worth buying an entire carbeurator on amazon for $20-30 bucks instead of just the solenoid Gets you a fresh carb, and is sometimes cheaper than a rebuild kit. The alcohol in fuels can eat up your seals, as most lawn mower carbs are not alcohol resistant.
One example below, but you need to pull your parts diagram for your model. This one has a rubber tip, which disolves or hardens, so most likely to fail.
One example off amazon for the entire carbeurator, including the solenoid for under $20