Why is it desirable to inject reactive power into a transmission system?
The main reason for reactive power compensation is to regulate the voltage magnitude. Note that the compensation might be both positive and negative (reactive power in, or reactive power out). In a transmission system, there is a strong correlation between reactive power and voltage magnitude, whereas the active power is mainly dependent on the voltage angle. Have a look here for a bit more information.

In the transmission system, a branch might have impedance Z = R + jX, where the reactive X is about 10 times the purely resistive R.

I'm assuming you're familiar with the per unit system. Let me know if you're not and I'll explain it closer. 

Let's just review a few basic relationships first:

\begin{align*}
S = V \cdot I^*\\
=&gt; I = (S/ V)^*\\
\Delta V = I^2\cdot Z\\
Z = (R + jX)
\end{align*}

Let's assume we have a very simple power system that looks like this:

G ---|------------------|------------------|-----&gt;
     3   Z = R + jX     2   Z = R + jX     1   Load               



G is the generator
The verticals lines are buses, labeled 1 - 3
The load is at the end of the radial.
The voltage at bus 1 is assumed to be 1pu with angle 0 degrees.
The load is (1 + j0.2) pu. (If S_base = 100MVA, this would be equal to 100MW + 20MVAr)
Z = 0.01 + j0.1


The current necessary to supply the load is given by:

\begin{align*}
I = (S/ V)^* =((1 + j0.2) / 1)^* = 1 - j0.2\\
\end{align*}

No compesation:

The voltage at bus 2 is give by the voltage at bus 1 plus the voltage rise over the cable (seen from 1 to 2):

\begin{align*}
V_2 = V_1 + I^2 \cdot Z = (1-j0.2)\cdot(0.01 + j0.1)
= 1.054\angle 5.01 ^{\circ}\;\text{pu}
\end{align*}

This means the power injection into the cable between 1 and 2 is:

\begin{align*}
S_2 = V_2 \cdot I^* = (1.031 + j0.302) \;\text{pu}
\end{align*}

The voltage at V3 is:

\begin{align*}
V_3 = V_2 + I^2 \cdot Z = 1.11\angle 9.50^{\circ}\;\text{pu}
\end{align*}

Now we can find the power output from the generator by using the first equation:

\begin{align*}
S_{Gen} = V_3 \cdot I^* = (1.062 + j0.404) \;\text{pu}
\end{align*}

With compensation:

Let us add a capacitor that injects 0.3pu reactive power at bus 2.

The voltage at bus 2 is still given by the voltage at bus 1 and the voltage rise over the cable, so it's still \$\underline{1.054 \angle5.01^{\circ}\;\text{pu}}\$.

Now, the reactive power injection of 0.3pu will give a current injection of:

\begin{align*}
I_{inj} = (Q / V_2)^* = 0.285 \angle{-85.0}^{\circ}\;\text{pu}
\end{align*}

The current through cable 1-2 is equal to the current through cable 2-3 plus the current injection, so:

\begin{align*}
I_3 = I_2 - I_{inj} = 0.979\angle 4.90^{\circ}\;\text{pu}
\end{align*}

You see that the current magnitude is lower than it was without compensation. So, let's have a look at the voltage at bus 3:

\begin{align*}
V_3 = V_2 + {I_3}^2 \cdot Z = 1.06\angle10.22^{\circ}\;\text{pu}
\end{align*}

Now we can find the power output from the generator by using the first equation:

\begin{align*}
S_{Gen} = V_3 \cdot I_3^* = (1.037 + j0.096)\;\text{pu}
\end{align*}

So, to summarize:

       W/O comp:   W comp:
|V1|   1.000       1.000
|V2|   1.054       1.054
|V3|   1.115       1.060

       W/O comp:         W comp:
Gen    1.062 + j0.404    1.033 + j0.096


As you can see from the above results, the voltage is much more stable with compensation. The current gets lower through the cable resulting in lower active losses. 

The reason why the reactive power is needed in the first place is because it accounts for the magnetization of the equipment. If there's no reactive power, transformers, generator rotors/stators, machines etc. have no magnetic field. With no magnetic field, there is no torque, no magnetic coupling in the transformer etc. So, a lot of equipment have to consume reactive power in order to work. If there's too little reactive power available the equipment will try to draw more current to compensate. This will lead to higher voltage drops, which in the end might cause voltage collapse. 

As Andy points out, it can also be used as power factor correction for large industrial loads. However when we're talking about reactive power compensation it's most often because of what I've described above.

In a meshed grid it can also be used to control power flow. This works because the active power flow through a cable is mainly given by the voltage angle difference over it. If you inject reactive power, the voltage and currents angles will change, thus it will affect the power flow. If you inject the right amount at the right place you can redistribute the power flow the way you want (but only to a small extent).

Hope this answers your question!