...natural gas...
...I'm not sure what the different parts are here...
Those two statements together equal "call a gasfitter".
Removing the appliance will leave the gas line unsupported, and that will lead to failure at the supported end off to the right.
The cap you want to install must be properly sealed or it will leak. Maybe now, maybe later. If the shutoff valve is faulty it will leak quite a bit of gas when you open the union.
Do you have non-sparking tools? Natural gas ignites very easily and burns very, very well.
A gasfitter will remove the pool heater, cut the pipe back to a proper place and cap the line properly. They will probably also dispose of the heater for you.
The worst-case for a do-it-yourself gas service is your house explodes. Another possible outcome is a nasty fire, with you standing in the middle.
And it's probably illegal for you to do this work yourself, which means if your house explodes your insurance will not pay out. Not an issue for you if you are home at the time, but your beneficiaries might be upset.