If Mary had had other sons besides Jesus, it would have made little sense to assign John to be her son. But let's look at the Biblical evidence.
Is not this the carpenter's son? is not his mother called Mary? and
his brethren, James, and Joses, and Simon, and Judas? (Matthew 13:55)
Is not this the carpenter, the son of Mary, the brother of James, and
Joses, and of Juda, and Simon? and are not his sisters here with us?
And they were offended at him. (Mark 6:3)
Note that these texts carefully avoid any connection of the brothers and sisters of Jesus to Mary, Jesus' mother. There is no text in the Bible that would indicate or confirm that Mary had any other children. The Bible, in similar fashion, carefully sets Joseph apart from a direct fatherhood connection with Jesus.
Now the birth of Jesus Christ was on this wise: When as his mother
Mary was espoused to Joseph, before they came together, she was found
with child of the Holy Ghost. (Matthew 1:18)
And when they were departed, behold, the angel of the Lord appeareth
to Joseph in a dream, saying, Arise, and take the young child and his
mother, and flee into Egypt, and be thou there until I bring thee
word: for Herod will seek the young child to destroy him. (Matthew
2:13)
And Joseph and his mother marvelled at those things which were spoken
of him. (Luke 2:33)
And when they had fulfilled the days, as they returned, the child
Jesus tarried behind in Jerusalem; and Joseph and his mother knew not
of it. (Luke 2:43)
None of those passages says Joseph was Jesus' father--because, of course, Jesus was not fathered by man. But why does the writer take time to say "Joseph and his mother" instead of simply saying "Jesus' parents"? The Bible is careful with identities where these are important. And it is important that a Bible student take notice, and interpret correctly.
In similar fashion, the Bible does not state that Jesus' brothers were the sons of Mary. Having just named Mary, it could have said "mother of James and Joses....etc." But that is not what it says. There is a reason for this.
By the time Jesus began his public ministry, Joseph had passed away--which is why we do not see or hear of Joseph at the wedding in Cana, as being among those waiting to see Jesus outside the crowd, at the cross, or upon any occasion during Jesus' ministry.
The other children of Joseph, for whom Mary was a step-mother, while still relatives of Mary, were not her blood relatives. She, being a woman, would have faced difficulties within the culture of her day if, following Jesus' death, she had tried to remove herself from her in-laws to seek a more peaceful residence. Jesus, knowing this, gave command that she consider John as her son, and that John take Mary as his mother. John, being close to Jesus, immediately understood the command, and took her to his home, caring for her as his own mother. This brought relief to Mary's mind, for Jesus' word gave legitimacy to her move.
Had Mary had other sons of her own, they would certainly have cared for her, and John's help would have seemed unnecessary. But there is simply no text to indicate that she did.
Jesus' brothers were those born to Joseph before his first wife had passed away. They were older than Jesus, which is why they felt especially upset when Jesus did not listen to them and follow their directions. When Jesus said "My mother and my brethren are these which hear the word of God, and do it" (Luke 8:21), he implied that those outside the crowd waiting to speak with him (they had something they wanted to tell him to do) were his family only as much as they followed his messages from God. Jesus was turning the tables--giving them instruction when they had come to give him instruction.
Within the culture of that day, it would have been unthinkable to seek to instruct a superior. This is why Jesus himself, as a twelve-year-old boy in the temple, merely asked questions of the teachers (see Luke 2:46-47). He could not directly instruct them, but through his questions he showed that he had a more thorough understanding than they had--and they learned from his innocent questionings.
Therefore, when we see that Jesus' brothers attempted to tell him what to do, we know that they were older than he was. And that is just what we see in John 7:3.
His brethren therefore said unto him, Depart hence, and go into
Judaea, that thy disciples also may see the works that thou doest.
(John 7:3)
Though Jesus loved and respected his brothers, he had a mission which they did not understand; and he followed his Father's will over theirs.
Clearly, as Jesus' brothers were older, and as Jesus was the firstborn of Mary (see Matthew 1:25), the brothers could not have been Mary's sons.
This is why Jesus, in perfect filial love and understanding of his mother's needs, assigned John to Mary.