40:34-35 And Joseph had already come to you before with clear proofs, but you remained in doubt of that which he brought to you, until when he died, you said, 'Never will Allah send a messenger after him.' Thus does Allah leave astray he who is a transgressor and skeptic." Those who dispute concerning the signs of Allah without an authority having come to them - great is hatred [of them] in the sight of Allah and in the sight of those who have believed. Thus does Allah seal over every heart [belonging to] an arrogant tyrant.
So the Quran clearly states that they shouldn't say "Last Prophet".
In this verse its "Rasool". Not "Nabi".
The confusion is in the use of English words "messenger" and "prophet" interchangeably, mostly out of no other choice. Also the verse you have taken is speaking of those who rejected Yusuf and his message or rather doubted him and his message. Also, the verse does not say "he was the last rasool". It says "they first reject his message, doubt everything about him, and when he dies they have the audacity to say there won't be any messenger after him". And 33:40 says last Nabi, not last rasool. So these are two completely different types of things in two different verses. I hope you understand that.
The title khatam an-nabiyyin or khatim an-nabiyyin, is applied to Muhammad in verse 33:40 of the Qur'an. The popular Yusaf Ali translation reads,
Muhammad is not the father of any of your men, but (he is) the Messenger of Allah, and the Seal of the Prophets: and Allah has full knowledge of all things.
— The Qur'an – Chapter 33 Verse 40
The verse 33:40 very clearly distinguishes between a rasool and Nabi. Because it says very clearly the he is the messenger of God or rasoolullah first and then says that he is the last Nabi. Thus if one wishes to argue that a rasool may come in the future, but the Quran is clear that Muhammed is the last Nabi.
In simple language hatham means 'seal'. I would use it when I finish something. If I finish reading the Quran I would say "hathamul Quran". End of the month I would say "hatham asshahar". Lets say you are drinking a glass of water and you say khatham (I added the k because people are used to it this way) it means thats the end of the drink. Its finished. There is no more to drink. Khaathamun, if applied to something I am writing it would be the last paragraph. There are no more paragraphs or writing there. Thats the end.
So the Quran is indeed, very vividly saying that Muhammed is the last Nabi.
One of the biggest issues in this matter is the lack of empathy towards another language. The word prophet and messenger are interchangeable in our minds. But if you stop using these words until you understand this passage it would be a better approach. The verse as I said already clearly differentiates between Rasool and Nabi. It says Muhammed is the last Nabi, but doesn't say he is the last Rasool. So one could argue that a rasool can come. And the Bahai argument is exactly that. So is the Ahmadi argument. EXACTLY THAT.
Islamic eschatological beliefs of the Mahdi and the return of Jesus are never found in the Quran. All of the concepts of an end-time figure be it the Mahdi, Al Qaim of there Shia's, Shirazi, Mirza Hussain, Dajjal (beast 666 the antichrist), return of Jesus, are all extra Quranic teachings that were interpreted that way.
The debate with Rasool and Nabi has been where the Muslims argue that Rasool brings a book, a Nabi is any messenger of God. Thus, last Nabi would mean that there will never be another person called a messenger of God. This is an argument to eliminate anyone claiming to bring any message from God. This is the typical muslim argument.
The Ahmadi's, Bahai's, followers of Rashad Khalifa argued that "Nabi is a book bringer", and "Rasool is any messenger of God". So even if there won't be a Nabi in the future, there could be Rasools. No more books, but messengers are possible. The variance in the Bahai argument is that after Shirazi, Bahaullah had a book.
If it doesn't mean Muhammad was the final Prophet for all time as believed by Muslims, what does it mean?
Typical Muslim argument
Nabi = Any messenger of God (No more means no more anything)
Rasool = Bringer of a book (Moses, Jesus, David, Muhammed)
Typical opposing argument
Rasool = Any messenger of God (Thus can be another in the future)
Nabi = Bringer of a book (Moses, Jesus, David, Muhammed. No more Nabi means there could be rasools)
Hope thats comprehensible. I am not making any judgment calls in this particular post, just answering the query.