This happens due to inertia, described by Newton’s First Law. When the bus is moving, your body is also moving with it. When the bus stops suddenly, your body wants to keep going forward because no external force has acted directly on you to stop you.
That’s why you lean forward. Seat belts and handrails help apply that needed external force to stop your motion safely and prevent injuries during sudden stops