As stated in the Summary, there are 3 main components (in my humble opinion) that contribute to the tone and quality of a[n electric] guitar.
The three most important factors ranked in importance from low to high begin with the hardware. Whether or not the bridge is secure enough to keep the guitar in tune, or how high the strings are set from the neck are probably the most beneficial factor affecting the sound quality of the guitar. Guitars with Tune-O-Matic bridges such as the SG or Les Paul from Gibson tend to stay in tune much better as well as Floyd Rose tremolo systems on guitars like the Strat. Other factors such as chrome hardware or whether the inlays are set in pearl, or just painted on dot acrylic; are purely aesthetic, but can greatly affect the price.
More important than the hardware would be the pickups. To name a few of the best quality companies to manufacture pickups (in no particular order) are Gibson, Fender, Seymour Duncan, DiMarzio and EMG. As just mentioned the pickups are the second most important factor in the sound of a guitar. To explain this let's take a look at music's most popular pickups:
Single Coil: Probably the most common, the single coil pickup produces bright clean tones. This guitar resides in most Fenders, particularly in Stratocasters and Telecasters.
Humbucker: This pickup thickens the tone and gives it some "bite" or "crunch". Commonly used on the Gibson SG, Les Paul, and Fender Stratocasters.
P-90 Pickups: P-90's are "jazzy" sounding pickups with brighter, more transparent sound without the thin crisp single coil sound. It has a good mid-range tone. These are also used on numerous Gibson SG and Les Paul models.
The third, final and most important component (once again, in my humble opinion) would be the wood the guitar is made of. Here's a quick overview of various guitar woods:
Basswood: Lower end/ beginner's guitars tend to be made of basswood because they're cheap and are readily available where the make most lower end guitars. They produce a clean tone and are used in many low end Fenders, and Ibanez's.
Mahogany: A dark wood, produces a very warm, full, rich, dark tone that fills the guitar. Most often used in conjunction with humbuckers or P-90 pickups. Most popular guitars for this wood are the SG and Les Paul.
Maple: Used in Strats, usually to make the neck, nice fair, white color, very light wood, again with clean tone.
Rosewood: Not commonly used as a body wood, but is glued on top of a maple or mahogany neck. Rosewood (according to the name) is a dark reddish color that provides a very nice look on the guitar.
Alder: Used in most high-end clean-toned guitars such as Stratocasters, Telecasters and PRS's. Has a very nice clean, crisp, definite tone.
The corresponding grains in the wood are what resonate the sound within a guitar, and are what vary the sound. If the grains in different parts of the guitar differ from each other; that is what produces a not very nice sounding, uneven tone. To expand on the topic of sound quality in wood; both the Les Paul and SG are made of mahogany, both are installed with humbuckers, so why do they sound so different? The answer is that the SG is a lot thinner than the Les Paul; and therefore sound is not as heavy as a Les Paul, but it's mahogany and humbuckers makes it darker than a Strat. These three things are what define that tone within a guitar and what style it will be able to play.
Hopefully this was helpful. Feel free to ask questions or raise concerns that contradict what I have written, or point out anything that might be incorrect.
* Note how I stress that everything written is my opinion; which I have developed through observation in my minimal number of years playing (2) and my personal experiences with guitars, I'm not a professional musician, nor review writer, I am simply giving my two cents on the matter of what I think makes one guitar better/different from another.