the E7 chord includes E G# B D. If we play E7 on the 5th fret, it is missing a B note. Could anyone please explain that?
In general, when you only have a limited amount of voices and you need to leave out a note in a chord, the Perfect 5th is the first to go. A Perfect 5th doesn't typically add a lot of color to a chord and thus typically when playing a chord it's viewed as OK to omit without changing the nature of a chord.
I will say for this specific chord, there's no reason you could not add the B by letting the B string be open instead of doubling the high E string.
It is common to omit a note from a chord, especially on a guitar, where 3-4 note voicings commonly sound the best, and also it's not always convenient to play all notes. In many cases perfect fifth is a note that doesn't add much to the chord and it can be omitted as in this case. So yes, this is a perfectly valid voicing of E7 chord.
In any chord, certain notes have certain importance.
The root is important as it gives the name to the chord. In this case, E7.
The third is important as without it, the chord will be neither major nor minor. An important factor in harmony. This one contains G♯, making it a major based chord.
Since it's a 7th chord, it needs that 7th part. Here a D note.
Often the 5th (P5) of a chord is omitted. Various reasons, one being that on guitar, it's not always possible to finger all the notes of a chord, so something needs sacrificing, and obviously the most important ones kept. Another being the 5th (B) often doesn't add anything to the sound of the chord, except it is a harmonic of the root, so is actually sounding when that root is played.
So 1,3,7 being the most defining, 5 gets left out, with no great loss. Except - there are B notes that could be played at that position on guitar. Leaving the 2nd string open is one, as all that string is doing is duplicating the top string open (a kind of 12-string sound), or the bottom string 7th fret can be pressed, giving a 2nd inversion of E7.