Different letters blend together to make a variety of phonemes (sounds) in English. Sometimes the same letters produce different sounds (for example the 'ea' sounds in 'beach' and in 'bread' are created using the same letters, but make different phoneme sounds). This is part of what makes English a complex language to learn, the sounds are quite complex. There is no hard and fast reasoning as to why in many cases. You just have to look at the surrounding letters and make the choice
A 'gh' combination is used in a number of phonemes:
The digraph (2 letter blend) sound 'gh'
cough
laugh
rough
trough
enough
The trigraph (3 letter blend) phoneme sound "igh"
light
high
bright
the quad (4 letter blend) phoneme sound 'ough'
bough
plough