This is a small part of a whole verse quoted in isolation, out of context. The verse in full form is in the context of a war and reads:
“Whatever gains Allah has turned over to His messenger from the inhabitants of the villages belong to Allah, the messenger, kinsfolk, orphans, the needy, and the traveller. This is explained so that you do not just circulate it among those of you who are rich, take what the messenger gives you and abstain from what he forbids you. Be mindful of Allah, Allah is severe in punishment.” (Qur’an 59:7)
It is clear that the portion:
“take what the messenger gives you and abstain from what he forbids you.”
is referring to the booty of war recovered which the messenger will distribute to those in need.
People take this portion of the verse and quote that part only, out of context, in an attempt to deceive people that the messenger has forbidden more things not found in the Qur’an.
Allah says the following with regards to these sorts who take portions of Allah’s verses, then deliberately hide or twist their meanings for vain gains:
“Among them is a group who distort the Book with their tongues so that you think it is from the Book when it is not from the Book. They say, ‘it is from Allah’, but it is not from Allah. They tell a lie against Allah and they know it.” (Qur’an 3:78)
Even if one were to follow along with their misunderstanding that this part is referring to absolutely everything the messenger forbade and permitted, then the “messenger” does not forbid or command anything other than what is found in his “message“, the Qur’an, and what is against the Qur’an is against the messenger:
“Messenger (رسول / Rasul)! Proclaim everything that has been sent down to you from your Lord – if you do not, then you will not have communicated His message (رسالة / Risala) ” (Qur’an 7:2)
“This [Qur’an] is sent down from the Lord of all the worlds. If [the Prophet] had said anything against Us, We would certainly have seized his right hand and cut off his artery, and none of you could have defended him.” (Qur’an 69:43-47)
The occasion when the Prophet forbade himself or someone something outside of the Qur’an is also reprimanded:
“Prophet, why do you prohibit what Allah has made lawful to you, in your desire to please your wives? Yet, Allah is forgiving and merciful…” (Qur’an 66:1)