I recently came across this sermon from Nahjulbalagha and it states that Imam Ali said that Prophet Muhammad had prevented them from wailing and mourning. Why do we mourn then?

Wailing is recommended for Imam Hussain (as) in many narrations.

When we have a loss in our lives we remember and mourn Imam.
I highly recommend this book

Commemorating the Mourning Rights of Imam al-Husayn https://smile.amazon.com/dp/1514298619/ref=cm_sw_r_cp_api_glt_fabc_25H7R9JH0X7R70JBFGW6

https://youtu.be/Fdt19d8E90Q