Why is this vector field curl-free?

The vector $\hat \varphi$ is not defined at the origin, because the coordinate transformation $$(x,y) \mapsto (r,\varphi) = \left(\sqrt{x^2 + y^2}, \arctan(y/x)\right)$$ is singular there. Hence your field $\mathbf B$ is singular at the origin.

The theorem that $$\nabla \times \mathbf B = 0 \Rightarrow \oint_C \mathbf B \cdot d\mathbf r = 0$$ requires that the curve $C$ in the line integral be contractible to a point without passing through any singularities. This is not the case for the plane with the origin excluded when the curve winds around the origin.

The singularity of course arises because you have an infinitely thin wire. Try finding the magnetic field for a wire of thickness $R_1$ with uniform current density and taking the limit of $R_1 \to 0$ while the total current remains constant. The curl will be zero outside the wire, but diverge inside the wire, as Maxwell's equations dictate.

There already are very good answers so I would just like to give some physical intuition why this vector field is curl-free even though it has non zero circulation.

We can make an analogy of the curl with an infinitesimally small paddle wheel in a fluid flow. We think of the vector field as a flow of the fluid and the paddle wheel plays the role of the curl. The direction of the curl is given by the axis of the paddle wheel and by the right hand rule. The magnitude of the curl is associated to the angular velocity of the paddle wheel.

If we put the paddle wheel in a fluid flowing accordingly to the given vector field, the fluid will push the paddles as in the figure below


The vector field is strong at the bottom paddle (closer to the center) and weaker at the top one. The net result on this two paddles would be to rotate clockwise. However the fluid also pushes the left paddle downwards and the right paddle upwards. This counter clockwise rotation exactly cancels the clockwise one from the top and bottom paddle and the net result is that the paddle wheel does not rotate. This vector field is curl-free although it clearly has a non zero circulation.

That formula is valid outside the wire, where $J=0$. Maxwell 's equation says that $\nabla \times B = 0$ there.

However there is no scalar field whose gradient is $B$ around the wire. This is the typical case where you have an irrotational field which does not admit a (global) potential. Otherwise the integral of $B$ around the wire would be zero and this is not permitted by one of Maxwell's laws in integral form.

Inside the wire if $J$ is uniform, $I$ includes only the portion of current sourrouded by the considered line of $B$, so it depends on $r$, i.e., $I=I(r)$ and the formula changes producing $\nabla \times B \neq 0$.