This incident occurs in Chapter Eight of this tremendous novel. Amir is obviously completely consumed by guilt at having stood by whilst Hassan was raped by Assef. He has found that he cannot live with the reality of what he didn't do, and seeks to find various ways of coping with this guilt. He starts a fight with Hassan because he wants to be punished by him for what he had done. Note what Amir himself tells us:
I hit him with another pomegranate, in the shoulder this time. The juice splattered his face. "Hit me back!" I spat. "Hit me back, goddamn you!" I wished he would. I wished he'd give me the punishment I craved, so maybe I'd finally sleep at night. Maybe then things could return to how they used to be between us.
Thus we can see that Amir wants to be hurt and beaten up so that he could have the "punishment" he knew he deserved in the hope that this would alleviate his guilt and shame at having abandoned Hassan to Assef.