Use the same script or IPython cell
If you run the code from the question inside the same script of notebook cell, it will produce the desired output, namely print the limits of the histrogram.

If, however, you really want to run it from different cells, you would run into the problem of pyplot forgetting about its content in subsequent cells. In that case you have two options.
Use the object oriented approach
working on the objects, in this case the axes, directly via the respective methods (ax.get_xlim
).
In[1]: fig, ax = plt.subplots()
ax.hist(data, bins=25, color='b');
In[2]: x_min, x_max = ax.get_xlim()
In[3]: print(x_min)
print(x_max)

Configure IPython not to close figures
You may use the IPython configuration to tell the backend not to close pyplot figures,
%config InlineBackend.close_figures=False # keep figures open in pyplot
In that case the code from the question would even work in different cells.

Similar question has also been asked here: How to overlay plots from different cells?