This is a common question, when customers enter our store. We take possibly voiding a warranty so seriously that we even have a small bit about it to separately initial on our work order forms.
With that said and simply said, if you phone is worked on or opened by an individual or company that is not Apple Inc, you void your warranty. (like they guy said above that is if they know and they can see it) So make sure you go with a Pro Shop for your repair. Another reason why replacement screens can void your warranty is because just like our company Device Savers, we do not know the unforeseen of a rookie tech repairs. They could have done a great job on the screen repair, but messed up your charger port in the process, which is very common for non-pro's. Why would we warranty the device, when someone else caused damage to it. So simply said if Apple can see and prove that someone else has been in your device it voids the warranty.
There are also many other instance that can void the warranty, such as cracking the screen, water damage, heck even if there is any cosmetic damage to the device the warranty can be voided.
The warranty does not cover cosmetic damage, so a scratched screen will not be repaired/replaced to fix the scratch. However, Apple will determine, on a case by case basis, if the cosmetic damage actually indicates a cause for any functional or other hardware defect or improper functions.
You can indeed bring in a cosmetically flawed device for service under warranty for defective components to Apple. However, the only time cosmetic damage will void the warranty entirely is if it is determined to indicate accidental damage, abuse or mis-use of the device in some way as to void the warranty. But that is decided on a case by case basis, and there is no blanket rule governing such instances.
You can read your warranty here - https://www.apple.com/legal/warranty (pick your country from the bottom right flag symbol). In the USA, for an iPhone, the main paragraph covering the issue you raise would be:
"This Warranty does not apply: (a) to consumable parts, such as batteries or protective coatings that are designed to diminish over time, unless failure has occurred due to a defect in materials or workmanship; (b) to cosmetic damage, including but not limited to scratches, dents and broken plastic on ports; (c) to damage caused by use with another product; (d) to damage caused by accident, abuse, misuse, liquid contact, fire, earthquake or other external cause; (e) to damage caused by operating the Apple Product outside Apple’s published guidelines; (f) to damage caused by service (including upgrades and expansions) performed by anyone who is not a representative of Apple or an Apple Authorized Service Provider (“AASP”); (g) to an Apple Product that has been modified to alter functionality or capability without the written permission of Apple; (h) to defects caused by normal wear and tear or otherwise due to the normal aging of the Apple Product, or if any serial number has been removed or defaced from the Apple Product."
Note the separate statements - that cosmetic damage itself is not covered, nor is damage caused by accident, abuse or misuse. However, whether anything falling into the former criterion actually constitutes voiding of the warranty by the latter criterion will be determined by Apple when you present an item for warranty service. One thing does not automatically imply the other.
Hope this helps!