The dot com crash helped none of course, the $2Billion Cobalt Network acquisition was particularly dumb. However by 2007 they were no longer in red, they had just spent a billion on MySQL that year and were in decent financial shape.
Sure they weren’t growing, but there was no urgent need to sell . They could have stuck around and who knows MySQL or Open Office could have grown or even Java Licensing from Android adoption or be selling hypervisor or core tech to then emerging cloud tooling OpenSolaris had ZFS , Containers, DTrace and some really cool software that Linux simply lacked. Sun had developer mindshare and ton of goodwill which would have quite valuable to just anyone not named Oracle particularly so around the Ballmer years.
Oracle itself is a testament that sticking around pays eventually, for that matter NVIDIA stuck around to twice ride a hype cycle first the crypto one and now AI.
The board and management just didn’t have any vision so jumped at the second offer, that is hardly attributable to dot com burst, just poor management.
Even selling to Big Blue, when IBM came knocking first would have been better for everyone(including arguably also Oracle). Oracle was and is not to be equipped to engage with the developer community.