This is a a numerical analysis issue.
You're holding decimal objects in your numpy array for some reason, and this gets converted into the Object dtype. When you try to perform matrix inversion, the matrix gets converted into float (I'm guessing with low precision).
The condition number of a matrix helps us understand how hard it is to invert the matrix (see wikipedia for a more formal definition). If you check B using np.linalg.cond (make sure to convert to a numpy dtype first) you will see the condition number is around 1e18 (which is very very high).
Another way you can think of it if you know some linear algebra - the determinant of a matrix allows us to determine whether the matrix is singular or not. Det(B) = 0 means the matrix is singular. In your case you created a matrix for which calculating the determinant is very easy (upper triangular).
The matrix is upper triangular, for which the determinant is simply the product of the diagonal, which is (1/12)**(n_grid). This is why as ngrid grows, the matrix is nearly singular, and for the floating point precision you have (which I'm guessing gets converted to 16 under the hood), the matrix is essentially singular / non-invertible.
If you fix your code, which I took the liberty of doing, the implicit np dtype is float64, and the inversion works as desired.
I took the liberty of slightly modifying your code to make it work (ngrid wasn't defined) (changed ngrid to 19 to check).
import numpy as np
ngrid = 19
I_1 = np.eye(ngrid, ngrid, k=0)
I_2 = np.eye(ngrid, ngrid, k=1)
I_3 = np.eye(ngrid, ngrid, k=2)
B = I_1 + 10.*I_2 + I_3
B = np.divide(B, 12.)
print(np.linalg.cond(B))
B_inv = np.linalg.inv(B)
C = B.dot(B_inv)
assert np.diag(C).sum() == ngrid