How could the people at the time of Noah know they were living in sin without a proper declaration of the law and righteousness?
Your question assumes that God owes mankind a "declaration of righteousness" or some other explanation of the standards of God and the consequences of sin, but the Bible makes no such promise. On the contrary, the Bible says God owes mankind nothing except judgment:
In the beginning, mankind willingly traded a knowledge of God for the desires of the flesh, and in so doing they departed from Him and came under condemnation. The wrath of God is revealed against all unrighteousness, and only by His grace do some receive mercy instead. God owes no one His mercy, which is why His mercy is called “grace.”
In the time of Noah, the world reached a peak of sinfulness:
Therefore, the Lord was moved by the sin of mankind to destroy all life, yet in mercy the Lord gave favor (i.e., grace) to Noah and his family resulting in their salvation. Only Noah’s family received His mercy, and we have no reason to assume that God warned anyone else in humanity about the coming judgment nor did God give opportunity for the world to repent. In fact, Jesus says the world was completely unaware of the coming judgment:
The people of Noah’s day had no idea a judgment was about to come, and Jesus says that in the last days the Lord will act in a similar way bringing judgment against an unholy world without warnings or explanations. Such is the sovereign prerogative of a holy and just God to save those He desires and condemn those He desires, as Paul says:
For more information on this difficult topic, please consult the following resource: Wrestling with God