The passage here in John 10:1, 11, 14 is a direct reference to Jesus as LORD and Shepherd of His people in Psalm 23. Peter also refers to this in 1 Peter 5:4 where he calls Jesus, "The Great Shepherd" and the elders of the church are thus, by extension, the under-shepherds of the people.
Note the explanation of the Pulpit commentary on John 10:1 -
He that entereth not by the door The Oriental sheepfolds are commonly walled or palisaded, with one door or gate. Into one of these
enclosures several shepherds drive their flocks, leaving them in
charge of an under-shepherd or porter, who fastens the door securely
inside, and remains with the sheep all night. In the morning the
shepherds come to the door, the porter opens to them, and each calls
away his own sheep.
Jesus then expanded the metaphor in V7-9 -
“Truly, truly, I tell you, I am the gate for the sheep. All who
came before Me were thieves and robbers, but the sheep did not listen
to them. I am the gate. If anyone enters through Me, he will be
saved. He will come in and go out and find pasture.
Jesus is uttering here well-known truths:
- That the only way to enter the kingdom of God is via the gate/door of Jesus - all other ways of entering the "sheep pen" are invalid
- The sheep (= Christians) inside the sheep pen are safe while even Jesus is the door because intruders are kept out - that is, Jesus protects His people
This aspect is an allusion to the way ancient oriental shepherds worked. Small stone enclosures capable of holding a normal flock were scattered over the countryside. At evening the shepherd would seek one of these, usher the sheep inside and then sleep in the doorway/opening to protect the sheep while he slept.
Thus, Jesus cast himself as caring for and protecting His people.