Why did Buddha refrain from finding knowledge of the whole universe? I know that lord Buddha refrain from finding the all the laws of nature from science, everything in universe.(Understanding the whole truth of the universe). I like to know the reason for this.
Is it because our knowledge about the universe is so weak that we don't see anything, nor that the universe is so big that it is endless, (please correct me if i am wrong about this)? I know that lord Buddha mentioned the endless expansion and collapse of the universe. This phrase follows with Gibbs free energy theory, where everything goes to disorder. To make things into order it causes energy.
Like keeping the mind in one place is very hard. If I find nibbana in the coming up life, maybe I will realize that it is not meaningful. Currently I like learning new things in science, like I love reading books of prof. Hawkings teachings... Will all this knowledge be worthless if I find nibbana someday?
Also I am confused of the fact that Lord Mugalan did try to find the whole truth of the universe by meditation. Is it true that he got caught in a infinite loop and Lord Buddha saved him?
I like to know the reason for this.

Conjecture about [the origin, etc., of] the world is an unconjecturable that is not to be 
conjectured about, that would bring madness &amp; vexation to anyone who conjectured about it.

https://suttacentral.net/an4.77/en/thanissaro
In plain english, the reason for this is that these types of questions are not required for the path towards nirvana at best, or straight up misleading at worst.

Will all this knowledge be worthless if I find nibbana someday?

I wouldn't put down a physicists knowledge of the world, but it has little or nothing to do with buddhas dharma.