How to count the crossing number of a knot with $5$ crossing? We know that the linking number is always an integer. But for these two diagrams, I get linking number $-5/2$ and $5/2$. What's wrong?

 A: You're not computing the linking number, because the linking number is a property of a link with two components. Note also that when computing the linking number, you only consider crossing where the first knot crosses over or under the second knot, you don't count self-crossing.
What you're computing could be called the "self-linking number", but it's actually called the writhe. And in fact you're computing half the writhe. In the definition of the writhe, you don't divide by $2$ when you're done summing all positive and negative crossings.
Moreover you have to be careful, because the writhe is not an isotopy invariant, it doesn't make sense to talk about "the writhe of a knot", only "the write of a knot diagram". To convince yourself, do a Reidemeister type I move on one of your diagrams and compute the writhe again.
A: A framing of an oriented knot $K$ has a few possible descriptions.  I will go with the definition that a framed knot is an embedded ribbon $S^1\times [0,1]$, rather than just an embedded circle $S^1$.  This is meant to represent a basis of vectors normal to the knot, continuously varying along it.  The framing consists of a continuous family of knots, with $S^1\times\{0\}$ being $K$ itself and $S^1\times\{1\}$ being a knot $K'$, a knot "pushed off $K$ along its framing."
The self-linking number of a framed knot $K$ is the linking number between $K$ and $K'$.  Knot diagrams come with a standard framing, called the blackboard framing, obtained from imagining that we thicken the knot into a band that is everywhere parallel to the "blackboard" that the diagram is presumably drawn on.  The self-linking number of the blackboard framing from a knot diagram is called the writhe of the diagram.
For example, given your diagram of $5_1$, the following shows the blackboard framing and the calculation of the linking number.  Each crossing in $5_1$ contributes two negative crossings, and $-10/2=-5$, which is indeed an integer.

It's worth pointing out that every framing can be represented as the blackboard framing of some diagram.  The following diagram is a hint:

(This might give more intuition for why "writhe is not a knot invariant.")
So, might have gone wrong with your calculation, beyond just observing that that's not how writhe is calculated?  Given two non-intersecting knots $f_1:S^1\to \mathbb{R}^3$ and $f_2:S^1\to \mathbb{R}^3$, there is a Gauss map $f:S^1\times S^1\to S^2$ defined by $$f(s,t)=\frac{f_1(s)-f_2(t)}{\lVert f_1(s)-f_2(t)\rVert}$$
which works out because the denominator is never zero.  The linking number of the two knots is the degree of this map, which if you haven't heard of it roughly counts how many times the domain is wrapped around the codomain, counted with a sign determined by whether the orientation is reversed, and the degree can be calculated via an integral, supposing the knots are differentiable.  Without the push-off, $f_1=f_2$, and so $f$ has a singularity along the line $s=t$.  What you did was calculate half the degree of this map away from this singularity.  (More evidence of oddity is that it appears the Gauss linking integral away from this singularity converges to $0$, but Mathematica is very unhappy with the behavior of the integral so I cannot say for certain.)
