This follows from the relationship between the $\mathbb{Q}/\mathbb{Z}$ linking form of a $3$-manifold and the intersection form of a $4$-manifold that it bounds. Suppose that $W$ is 1-connected ($H_1=0$ would suffice) with $\partial W = Y$ where $Y$ is a rational homology sphere; everything is oriented here. Let $q_W$ be the intersection form on $H_2(W)$ with respect to a basis and let $\lambda_Y$ be the linking form.
From the long exact sequence $ 0 \to H_2(W) \to H_2(W,Y) \to H_1(Y) \to 0$ and Poincaré duality, we get that $H_1(Y)$ is the cokernel of $q_W$, and with some additional work you learn that $\lambda_Y = -(q_W)^{-1}$ where one is using a basis for $H_1(Y)$ coming from the chosen basis for $H_2(W).
Now if $W$ has $b_2=b_2^+ = 1$, the map $q_W$ must be multiplication by some integer $p > 0$. So the recipe above says that $H_1(Y) = \mathbb{Z}/p$, and the linking form is isomorphic to $(-1/p)$. The forms on $\mathbb{Z}/p$ isomorphic to $-1/p$ are exactly those of the form $-n^2/p$ for some $n$ relatively prime to $p$. Now the linking form of $L(p,q)$ is isomorphic to $q/p$ (with respect to some orientation convention that I'm certainly not going to work out here!). Hence we see one direction.
To go the other way, suppose that $Y$ is a rational homology sphere with $H_1(Y) = \mathbb{Z}/p$ and linking form $\lambda_Y(g,g) = -1/p$ for some generator. Then add a handle along a loop representing $g$ to get a $b_2=b_2^+ = 1$ cobordism between $Y$ and some $Y'$. If you do the framing correctly, then $Y'$ will be a homology sphere. So far everything has been smooth, and in general that's as far as you can go. But in the topological category, $Y'$ bounds a contractible manifold; gluing that to the cobordism gives the desired $W$.
Notes:
- I haven't been careful about orientations but it should all work out as stated.
- It takes a little work to determine what framing (and how to describe it) you need in the second argument. The original source for this is Kervaire-Milnor, Groups of Homotopy Spheres.