It depends entirely on where the file comes from — the blanket answer that all downloads are illegal is simply wrong.
Downloading from an official storefront, a publisher's own site, or a legitimate free release is completely legal; that is how most PC gaming now works. Downloading a commercial game from a file host or a piracy site is copyright infringement, and it also happens to be the most common way people end up with malware.
So the useful question is not "is downloading legal" but "is this source authorised." Check that, and the answer takes care of itself.