This updated method works for Windows 7, Windows 8.1, and Windows 10 as of May 2019.
Microsoft has made clean retail ISOs of Windows significantly more difficult, but not impossible, to get directly from their servers in recent years. As of 2019, it appears that the easiest way to download older versions of Windows is to use this utility, which allows you to generate download links for almost any version of Windows or Office released in the last decade. (Note that you still need a product key to activate any of these downloads, and all of the files are served directly from Microsoft servers (they just made them really hard to get to without external tools like this utility or the script given above by Ramhound), so this shouldn't be considered piracy in any way.)
It does open an extra window at launch with an ad, but it's simply a single AdSense banner in an iframe that's used to pay for keeping the download links up to date and is relatively harmless.
To download Windows 7, first select "Windows 7" in the sidebar. This will open another page allowing you to select the edition you want.
Choose the edition you want, and another prompt will pop up allowing you to choose language. If the language you want is grayed out, then Microsoft has temporarily disabled those links, in which case you need to switch over to the "Windows 7 (August 2018)" option and use it instead. Once one of the two options lets you select the combination of language and architecture you want, click the "Copy link for 64 bit" or "Copy link for 32 bit" in the right sidebar. Then paste that into your choice of browser or download manager (you'll notice that it is in fact on a microsoft.com domain, these are not rehosted) and download the resulting ISO.
Now that you have it downloaded, you probably want to validate that it is a real Microsoft-issued image. Luckily, you can do that easily with this web tool which contains the SHA-1 hashes for every single file offered up to MSDN subscribers, which includes almost all Windows images.
Simply grab the SHA-1 hash of the ISO you just downloaded (if you don't have a way to do that, 7-Zip includes a tool to do so) and paste it into the search bar and your desired Windows edition should be listed.
Note that I did say almost all Windows images; Microsoft doesn't offer certain OEM images and for whatever reason Windows 7 Home Basic to MSDN subscribers, so those hashes are not included in the database. Thus, if you want those images, you'll have to either trust the supplied link or download/verify the files a different way.
Moral of the story: Microsoft really wants you to upgrade to Windows 10.