How can I upgrade to any macOS version that is no longer available in the Apple app store?
As soon as a new Mac OS is released, the previous one becomes unavailable.

The only way to get an older OS directly from Apple is to have previously 'purchased it' - even if it was free - then it will appear in your purchase history in the App Store. 

If it's not in your purchase history, then you'll have to get it from a trustworthy friend [or less-trustworthy torrent etc]  

10.10.anything will do, as you can still get the combo updater to 10.10.5

It's always wise to get a new OS download, even if you don't intend to install it right now - just so it's always in your history.  I have every OS back to Lion in my purchase history - good for if I ever need a disposable OS for testing etc.



As Sierra will not run on older machines, this rule has been relaxed for machines whose last supported OS is El Capitan.
You can download it from here - https://itunes.apple.com/app/os-x-el-capitan/id1147835434?mt=12 - but it will not run if your machine is capable of running Sierra.
If it is capable, then you are back to needing it in your purchase history already.