The Jews and latter Christians had a habit of writing books and then ascribing them to a noteworthy person of the past. In other words, write a book and name it for example after the person Daniel and people will read it with more interest than if they had put their own name.
Barnabas may have been an early christian with Paul but did not leave any writings; many writings in the Bible attributed to Paul are not his either! Later on people wrote stories and some have attributed the Epistles of Barnabas to him but without any evidence.
The Gospel of Barnabas we have today, whether 5th century or more likely 10th century, is a forgery along the lines that I have already mentioned. The fact that Muhammad is mentioned should not overshadow the many problems with this book and we should place no importance upon it. No christian is going to accept it either.