However Buddha in MN 22 asks to give up Dhamma
Not "dhamma" but "dhammas". You quoted:
By understanding the simile of the raft, you will even give up the teachings, let alone what is against the teachings.
Kullūpamaṁ vo, bhikkhave, dhammaṁ desitaṁ, ājānantehi dhammāpi vo pahātabbā pageva adhammā.
And Ven. Sujato's comment for that line says,
Dhammā in the plural refers back to “those teachings” (tesaṁ dhammānaṁ) of the nine categories. Accordingly, when this simile is invoked at MN 38:14.1, it is in reference to views. The pair dhamma and adhamma usually means “the teaching” and “against the teaching” (eg. AN 2.104). The negative form has a stronger sense than simply “not the teaching”; it implies there is something unnatural, in conflict with the way the world is.
Dhammā in that sentence is plural -- it ends with a long
ā, see for example this reference:
Ven. Sujato translates that as "the teachings".
The Buddha-Dhamma as a whole is normally singular -- see for example here (where the Pali says
dhammo i.e. singular):
Ven. Sujato says that "teachings" (plural) here is a reference to this earlier paragraph (which he says in another comment was an early i.e. before the First Council way to organize the texts):
Take a foolish person who memorizes the teaching—
statements, mixed prose & verse, discussions, verses, inspired exclamations, legends, stories of past lives, amazing stories, and elaborations.
But they don’t examine the meaning of those teachings with wisdom,
and so don’t come to a considered acceptance of them.
They memorize the teaching for the sake of finding fault and winning debates. They don’t realize the goal for which they memorized them.
Because they’re wrongly grasped, those teachings lead to their lasting harm and suffering.
Why is that?
Because of their wrong grasp of the teachings.
So in context, "giving up the teachings" could mean "giving up arguing over who said what" -- or, "don't only memorize the words but 'examine the meaning of those teachings with wisdom'".
In contrast to the above there are other translators who don't translate "dhammas" there as "teachings". Remember from the Definitions for dhamma that it has several meanings, one of which is "mental state".
In this translation for example it's translated as "dhammas" not "teachings".
Understanding the Dhamma as taught compared to a raft, you should let go even of Dhammas, to say nothing of non-Dhammas.
Immediately after that there are sections inclduing
- Six View-Positions
- Agitation & Non-Agitation
Perhaps these are the "dhammas and adhammas" which we are to abandon.
Or maybe it means more generally, "good things and bad things", "good and bad mental states".
Piya Tan says here that,
Buddhaghosa, in his Commentary, interprets the reference to going beyond “good things” more specifically as a warning regarding the danger of being attached to meditative experience:
21 “You must let go of even good things …” Here “good things” (dhammā) means calm and
insight (samatha,vipassanā). The Blessed One says that desire-or-lust (chanda,rāga) is to be abandoned by both (pi) calm and insight. How does he do this with regards to calm?
“Thus indeed, Udāyi, do I speak of the abandoning of the sphere of neither-perception-nornon-perception. Do you, Udāyi, see any fetter (saṁyojana),
tiny or great, whose abandonment
I do not speak of?” [M 66,34/1:456]. Here, desire-or-lust is to be abandoned through calm.
“Bhikshus, no matter how pure, how clear, this view may be, if you do not stick to it, do not
prize it, are not acquisitive about it, do not treat it as a possession…” [M 38,14/1:260 f]. Here,
desire-or-lust is to be abandoned through insight.
But here, in reference to abandoning both, he says, “You should abandon even the dharmas,
how much more so that which are not dharmas!”
22 This is the gist: “Bhikshus, speak of the abandoning of desire-or-lust even in such things
that are profoundly calm (santa,paṇītesu). How much more then in respect to this wickedness,
vulgarity, baseness, crudeness, that which requires ablution, wherein this foolish one, Ariṭṭha,
perceiving no fault, says: “There is no obstruction in having desire-or-lust in the 5 cords of sensepleasure.”
“Do not, like Ariṭṭha, throw mud or rubbish on my teaching!” Thus the Blessed One rebuked
Ariṭṭha with this admonition. (MA 2:109)