When you wipe your phone and re-install a ROM, or switch to a new phone, you will be prompted to sign in with your Google account. As long as you use the same Google account, you will be able to find your purchased apps in the
Market by pressing the
Menu key and selecting
My Apps, or something similar (i believe they're named differently in different versions). From there you will be able to view and re-install previously purchased apps.
NOTE: This only works for apps you've spent money on. If it was free, it will not be stored on your account in this way.