When a string is plucked, it vibrates at a certain frequency, which is determined by the tension of the string and the mass of the string. The tension of the string is determined by the length of the string and the amount of force applied to it. The mass of the string is determined by the material of the string and the thickness of the string.
The vibrating string causes the soundboard of the guitar to vibrate, which in turn produces sound waves. The frequency of the sound waves is the same as the frequency of vibration of the string, which is determined by the tension of the string and the mass of the string. The pitch of the note is determined by the frequency of the sound waves.
So, the longer the string, the lower the tension of the string, and the lower the frequency of vibration of the string, and the lower the pitch of the note. Conversely, the shorter the string, the higher the tension of the string, the higher the frequency of vibration of the string, and the higher the pitch of the note.