To me the cap question is moot in the short term since you need to pay a QB eventually and Garoppolo's signed for three more years and by the time it's 2022, $27m will probably be very modest for a good QB. Don't get me wrong, I have all the same questions about him as you do, but because the Patriots would get him in a trade, they'd face no dead cap if he didn't work out so it's not a Goff situation where you've necessarily handcuffed yourself to a mediocrity.
To your point, I think you can do both, trade for Jimmy and then this gives you two or three seasons to find your Forever QB, be it Jimmy himself (if he answers all your questions affirmatively) or a draftee. Otherwise, I guess it really just depends on whether you think Stidham is ready and the return the Niners would demand for Jimmy (probably not much more than a 3rd since they'd need the room immediately for Brady). If you think Stidham is probably as good as Jimmy and/or some guy you'll find in the draft in the next couple years then it probably just makes sense to move forward with him.