Useless toil. Unappreciated endeavor. You can imagine it would be no fun to hit your head against a wall, thusly this phrase explains an unhappy chore. Often used as trying to teach someone something new but the student doesn’t learn.
“For the last two hours, I’ve been looking for your lost wedding ring in the beach sand, but I’m just knocking my head against the wall.”