Charles Leclerc was forced to pit after hitting the barriers in the closing stages of the Emilia-Romagna GP.