how could abaya be a friend to a sourcerer and why is he interested in helping him doesnt R Yochanan say you cant even look at a Rasha and this guy is robbing graves?
The Gemara in Sotah 41b teaches that it is permitted to practice Chanufah and flatter Resha'im in this world. Rabeinu Yonah (Sha'arei Teshuvah, Sha'ar 3:189, cited in our Insights to Sotah 42a) explains that the Gemara is referring to a Rasha who happens to be wealthy or powerful, and because of his wealth or power people would normally honor him by showing him respect. If degrading such a Rasha will cause personal damage at the hands of the Rasha, then it is permitted to act toward the wealthy Rasha in the same way that one would act toward any other wealthy person.
If the Amgusha was an influential person, it was permitted for Abaye to be friendly with him in the manner described by Rabeinu Yonah.
By the way, although the word Amgusha might literally mean sorceror (see Shabbos 75a, according to Shmuel), it is often used to refer to the Persian idolatous priests and missionaries who constantly persecuted the Jews (see Rashi Shabbos 139a, Gemara Sanhedrin 39a; these were also known as "Chavrei," see Shabbos 45a). Although Rashbam here writes Mechashef, he might mean this as well. These Persian priests were noted for their arrogance (see Shabbos ibid.; the priests' wickedness was deemed a punishment Midah k'Neged Midah for arrogance among Jews).
Along these lines, a beard sometimes represents an outward show of arrogance in one's intellectual capacity. As our Gemara says, it is the "Hadras Panim," see also Moed Katan 18a where the Gemara calls Para'oh an Amgusha after saying that his beard was as long as he was tall. In a non-literal interpretation, our Gemara might be saying that the Amgusha was punished for trying to rob the grave of the Amora by being caught red-handed and finding himself threatened with the public exposure of his abominable act. Abaye begged the person who found him not to embarrass the Amgusha and publicize the grave desecration. The second time, though, Abaye let the grave-robber's "beard be cut off."