بِسْمِ اللَّهِ means “in the name of Allah.” أَوَّلَهُ means “its beginning” and آخِرَهُ means “its end.” The pronoun هُ in each refers to the meal.
فَلَمَّا ذَكَرَ اسْمَ اللَّهِ means “then when he mentioned Allah’s name.” لَمَّا connects the action to a particular moment in the account.
The lesson is to remember Allah when the omission comes to mind, rather than continuing the remainder of the meal heedlessly simply because one forgot at the start.