The texts you mentioned, "For whoever is not against us is for us" (Mark 9:40) and "Whoever is not with me is against me, and whoever does not gather with me scatters" (Matthew 12:30), certainly do not contradict each other. They speak of different, although related, things...
The texts you mentioned, "For whoever is not against us is for us" ( 9:40) and "Whoever is not with me is against me, and whoever does not gather with me scatters" ( 12:30), certainly do not contradict each other. They speak of different, although related, things.
In the Gospel of Matthew, the Lord speaks to a person about his relationship with Him Himself. The main thing He wants to convey to the listeners (and readers) is that it is impossible to remain neutral towards God. God's will for the salvation of the world was that Christ would be revealed to all of us, and our relationship with Him becomes the cardinal choice of human life. In Deuteronomy, there are remarkable words: "I call heaven and earth to witness against you today, that I have set before you life and death, blessing and curse. Therefore choose life..." ( 30:19). Thus, our relationship with Jesus Christ is exactly this choice between life and death. It is clear that if a person does not choose life and does not live, then he chooses death—there is no third option, as they say. But this is the relationship between God and man.
When instructing the apostles, however, the Lord Jesus speaks about relationships between people. The primary call of the New Testament here is to always seek peace as much as it is at all possible. The Lord says in the Sermon on the Mount: come to terms quickly with your accuser while you are going with him to court. The apostle Paul writes in one of his epistles: owe no one anything, except to love each other... do not be overcome by evil, but overcome evil with good. By telling the apostles, "whoever is not against us is for us," the Lord is saying that if another person is not directly hostile towards us, then he cannot be an opponent for us either. In fact, Christ's radically new commandment speaks of love even for enemies—all the more reason a disciple of Christ cannot allow hostility and division on their own initiative. Christ repeatedly warned His disciples that their faith would cause hostility from people against them: "the hour is coming when whoever kills you will think he is offering service to God...". But the disciples must not respond in kind.
In practical life, this means that if you are not being nourished by the only Source of life—Christ—then you are not being nourished by anything at all, because there simply is no other source of life. At the same time, if there is an opportunity with someone to build "human," benevolent relationships without compromising communion with Christ, a disciple must not neglect it. And as for the one who is "against you," the Lord calls us to love them too: to pray for them and, if possible, to do good to them as well.