It is a very good idea to do your graduate study at a different institution as your undergraduate study, and to take a postdoctoral position at a different place from where you did your graduate study.
Even the best mathematics departments do not have strengths in every field, so being at several mathematics departments will broaden your education and expose you to a variety of mathematical cultures, including interesting tools and parts of mathematics outside of your existing fields of expertise. Furthermore, you will be able to interact over time with a greater number of mathematicians in your area if you study and work at different places, than if you stay at a single institution; given that a significant portion of one’s career advancement in a field is based in part on the recognition you and your work receive from your peers in that field, this can thus be quite beneficial to your future career in a mathematical area.
Furthermore, the act of moving will help you make the (substantial) psychological transition from an undergraduate student to a graduate student (in which you have to go beyond rigour and proofs), or from a graduate student to a postdoctoral researcher (in which one has to take the initiative rather than rely purely on your advisor). Staying in the same institution for these transitions may feel comforting and convenient, but it can slow down one’s mathematical development.
See also “Continually aim just beyond your current range“.