The way this argument progresses is intriguing. He starts by mentioning those who were apostatizing, preaching a false gospel, and rejecting what Christ had given the church in the gospel, yet he ends up speaking about contentment.
His thought is this: Those who argue against the doctrines of God and against the church are essentially discontent. They are at the initial stages of presumptuousness, or they may have already become fully presumptuous. They try to use their "godliness" to get some sort of advantage or gain for themselves. The motives on the surface may seem to be that they are trying to be godly, but underneath, the real motive is to get something for themselves.
We should not think of this "gain" as only money or goods. It could be respect, or favor with somebody. It could be notoriety or having people think that one is smart. It could be having authority of some kind - ordination or having a group of followers. It could be many things. What it comes down to is presumptuousness, because the person who does these things is reaching beyond his place.
God put the person in the body at a specific point, to do a certain job, and when he starts doing the types of things that Paul mentions - arguing against the doctrine, for instance - he is taking a job that he has not been given. Paul says the real gain comes when we behave in a godly manner and reckon that what we have is sufficient for us.