What actually happens if I vary proportions of cement and sand in mortar?
Codes and other guides provide nominal mix combinations that perform fairly in general conditions. 

In general, a 1:2 mix will give better strength than a 1:3 mix. But it is quite possible that a 1:0.5 mix might perform worse. Strength comes from inter-particle force transfer between sand grains and also from shear resistance provided by cement acting as adhesive. Thus codes provide known balanced combinations that are satisfactory.

To gain complete control over the properties of a mortar/concrete mix, you must consider the following criteria:


Cement Amount: As a thumb rule, increasing the cement increases the strength. Beyond a certain point, it also acts negatively. Since major force transfer in a concrete/mortar matrix is from sand-sand interaction, excess cement will turn the mortar very brittle since cement particles cannot transfer normal contact force - they are good at providing shear strength. Since cement is expensive, in low-strength applications like roads the amount of cement is less to optimize on the cost.
Water Amount: Generally water content ranging from 20% - 35% (w/w cement) is considering a safe operable range. Lower water content gives low strength and less manoeuvrable mix for flat conditions like road laying. Higher water content is generally used in specific conditions like laying out pile using tremie - where the free flowing nature of mix is necessary. Although high-water also leads to lower strength, there are other workarounds (mentioned ahead).
Sand Amount: A very high amount of sand will make your mix very brittle and weak against all kinds of forces. For M20, M25 etc, general proportion is 1:3. However, for High-strength mix (M35+) its better to go with 1:2 and somewhere about that.
Aggregate Amount: Aggregates have two reasons to be there - economy and strength. They are cheap and provide as a good filler. Very high and very low amounts of aggregate give poor strength but a varied economic solution. A moderate amount is good enough.
Aggregate shape: Generally, increasing crookedness of the aggregate particle gives increasing strength as it gives a higher contact area and better inter-lock capabilities.
Air Entrainment: A high air-content in the mix leads to lower strength. That's why high-strength concrete is vibrated before laying to expel the small air-pockets. A low air content gives low manoeuvrability, so sometimes, 'air-entrainers' (chemical additives) are used to give the desired flowing nature without compromising on changing the water content and consequently the strength.
Additives: Physical additives like 'fine-silica-powder', 'fly-ash' allow cement reduction and provide economy. fine-silica is ... very fine so it goes into the smallest of voids and provides good contact strength by reducing the air content. Fly-ash comes as a general replacement for cement. It is a by-product from thermal power stations and is very cheap. Upto 15% cement can be replaced by fine-silica and upto ~40% by fly-ash. Chemical additives like super-plasticizers do provide a effective workability increase, or even a water reduction at similar workability - thus giving a higher strength mix.