You are protected by the lease to live there for the entire term of the lease. If you do decide to leave prior the the term, you can find yourself in a legal battle for not living up to your lease. And if the bank does take over, which may not happen, the bank will have extremely good resources to recover the lost rent dollars.
If you have a lease, you are obliged to satisfy the conditions of that lease, which should include paying your monthly rent.
If the apartment is in foreclosure, it doesn't mean it's already bank-owned. Rather, the owner may be looking for ways to resolve his financial predicament through forbearance, loan modification, reinstatement, etc. If his tenants stop paying him rent, he'll be in worse financial shape.
If he is trying to do a short sale, he will want to show the property to prospective buyers. And he will need to provide financial statements regarding the income generated by the property. If you aren't paying your rent, he has every right to start eviction against you.
Unless you know the complete details of the pre- or actual foreclosure, how can you withhold rent?
If it is sold, and you don't have a lease, the new owner may not be bound by any agreement to keep you on at your current rate either and may give you notice to vacate, or increase in rent.