Consider three integers $x_1, x_2, x_3$ sampled from the integers $\{1,\dots,n\}$ uniformly at random (with replacement). I would like to know the probability that the median of $x_1, x_2, x_3$ equals $2$.
The probability that any of them equals $2$ is $1-(1-\frac{1}{n})^3$.
There are three possible mutually exclusive cases:
All three integers are equal to $2$. Probability of this case is $\frac{1}{n^3}$
Two integers are equal to 2 and the other one is not. Probability of this case is $\frac{3(n-1)}{n^3}$
One integer is less than 2 (that is equal to 1), one is greater than 2 (that is neither 2 nor 1), one is equal to 2. Probability of this case is $\frac{6(n-2)}{n^3}$
The total probability is $\frac{1}{n^3} + \frac{3(n-1)}{n^3} + \frac{6(n-2)}{n^3} = \frac{9n - 14}{n^3}$