How to download legally OSX if you don't have formatted Mac I've seen lot of guides how to install Yosemite etc which are "free to download" that start with "download OSX from Apple Store".

That is nice, but works only if you already have a working Mac that supports that target OS you want to get, otherwise you can't download them. In case you have a formatted Mac, some older model (I have mac mini from 2008), where online recover doesn't work - how would you download it?

There are torrents that contain .dmg file, but I don't think that is OK to use.
You can download any Apple software directly from the Developer portal: https://developer.apple.com/downloads/index.action

Not sure if the site is accessible to non-developers.