Refusals (and issued visa) are recorded in a database called the Visa Information System, for five years. Hungary will know about it but is free to make its decision independently, they don't have to ask Poland for permission and there is no reason for you to apply there first.
If you change your passport before it expires, not only will they still know that you were refused a visa (based on your name and date/place of birth or, possibly, your biometrics) but they will also notice you tried some deception tactics and that could weigh heavily against you.
Also, they will obviously know about the grounds for the refusal. Failure to adequately document your financial means for example would not be too bad if you remedied the situation in the meantime. But fraud would be very bad, no matter what you do afterwards.
For completeness, note that there is also another database called the Schengen Information System with completely different rules (you won't end up in there merely because an application was refused but only for more serious violations).
If there is a notice about you in the SIS, you have to contact the country that put a notice in the database and appeal the ban to (have a chance to) get a visa. A visa application cannot override such a ban and, legally speaking, another country can, at most, issue a “limited territorial validity” visa but not a Schengen visa (and, mostly, they will issue nothing, it's very easy for them: just a box to check without any further verification or need to justify anything).
Entries in the SIS have various automatic expiration delays but I think that a country can always reactivate an entry to keep it in the database as long as they wish, based on their national rules.