Can I cap off a gas line and leave it inside a closed joist space?
Either of the solutions you mention will work, but I recommend, if you have enough room, completely removing the elbow and installing a cap on the horizontal line in the floor. This way there are fewer connections, therefore fewer leak points. Of course, make sure you leak test any joints you move or work on.
There is nothing wrong with a gas line terminating in a floor, other than the difficulty of trying to use it for something in the future. But it's no more dangerous than having any other gas joint in the floor.
The ideal solution would be to find where that branch line begins, and cap it there. That way you remove all potential leaks after the origin point. However, I'm not sure that would be easy for you, as you stated that the basement is drywall-finished.
For your reference, here's a link to Minnesota's gas code. It says nothing about gas line terminations. It mentions that gas valves must be accessible, but that doesn't apply to your situation, as you will be removing the valve.
https://up.codes/viewer/minnesota/mn-fuel-gas-code-2015/chapter/4/gas-piping-installations#4