Typically gas stoves have a failsafe safety system that uses a thermocouple to keep the gas on only when there's enough heat.
If you used a timer to break that safety circuit (relay?), the solenoid will revert to it's safe state, and turn off the gas.
Doing that safely may be difficult. And doing anything with a gas installation may be illegal, depending on where you live.
https://www.mcmaster.com/gas-solenoid-valves/solenoid-on-off...
Combine with a countdown timer:
https://www.intermatic.com/Catalog/us/Products/In-Wall-Contr...
At ~$1200 DIY is a add-on fire suppression system for the range that would include a similar gas valve or contactor to shut down the range if fire suppression activated plus fire alarm klaxon and alarm system tie in possibilities.
[1] https://www.amazon.com/Beduan-Electric-Solenoid-Normally-Col...