No tienes por qué ir a la fiesta si no quieres.

Why is the “por” necessary?

It’s not necessary to have that “por” but it’s completely usual to say it like that.