Many scholars believe that the reason they were told to not preach to Samaritans and Gentiles was that his disciples were not ready to face cross cultural rejection. This is because of their earlier exposure to this rejection by Samaritans in which they wanted to respond by fire and brimstone. Jesus rebuked this response then. Later on, he instructs them to make disciples of all nations.
The passages in Matthew are referring to those that do not listen to his teachings (by choice), not the Gentiles. He’s saying they will not receive his blessings if they do not listen and learn from his teachings.