Maybe matplotlib used more strict checks and doesn’t like the additional channel dimension in your version, so you could remove this dimension, if needed.
It also works in my setup using matplotlib==3.4.2:
plt.imshow(np.random.randint(0, 255, (24, 24, 1)).astype(np.uint8))