Recently the sugar glycoaldehyde was detected in a star system 400 light years from Earth. How exactly are molecules detected in space? I am aware that spectroscopy is used to detect them, but I don't know the details. Please explain the methods involved.
This is a broad question. The energy levels occupied by molecules consist of a mixture of rotational and vibrational energy states. The values of the energies of these states are characteristic of particular molecules - they can be measured in the laboratory or occasionally need to be calculated if the molecules can only be formed in conditions found in space. A molecule may make a transition from a higher to a lower energy level. When it does so, the energy difference is emitted as a photon with a frequency corresponding to the energy level difference: $\nu = (E_2 - E_1)/h$.
Generally speaking, the differences in energy between these quantum states is smaller than of electronic transitions in atoms. This means that the photons emitted or absorbed, corresponding to these transitions are in the infrared, microwave or even radio part of the spectrum. What one measures is intensity as a function of frequency. If one is looking at a warm gas, then a pattern of emission lines will be seen at characteristic frequencies depending on what molecules are present.
In the case you mention, the observations were conducted with the Atacama Large Millimetre Array - ALMA, a microwave telescope. The molecules exist in a warm gas (a few hundred Kelvin) which excites certain transitions in the molecules and the emission of mm-wave (100s of GHz) radiation. This is then received by the ALMA instruments.
If you are looking for a treatise on mm-wave astronomical techniques, this is not the place. ALMA is able to detect microwaves with a high angular resolution, but also able to separate the microwaves out into narrow frequency windows of tens of kHz (i.e. it has good spectral resolution too).