If you are in the US, opening the iMac doesn't void the warrant, but if something goes wrong with your Mac unrelated to you opening it and Apple refuses to service it due to be opened by the customer, then you may have a small legal battle on your hands.
Reading the forums, I do not see too many examples of Apple rejecting warranty claims with the exception with other damage being involved, such as drops or water damage.
A few days after moving into my current home back in 2014, I found out that there was a very tiny leak in a pipe, which dripped onto the HVAC duct and dripped on the case on the back of my Late 2012 iMac.
It was only cosmetic damage on the aluminum, but I was upset about it tarnishing my otherwise mint iMac.
Around the same time, I started having Fusion Drive issues. The problems were clearly drive-related, but the Apple Store refuse to replace the Fusion Drive under warranty due to it passing their HW test. They would wipe the drive, only to have the issue come back, so back to the Apple Store. Each visit to the Apple Store would lead to a wipe, and the the return of the problem, first a month later, than weeks, then days after the wipe.
Eventually the drive totally failed, and the iMac wouldn't boot at all, not even in internet recovery mode. This was 12 days before the end of my AC warranty, and luckily, they finally replaced the drive.
The reason I bring this up is because every visit to the Apple Store, whatever "Genius" that diagnosed my iMac made the comment about the water damage on the case. They said that Apple will not honor the warranty if the water damage led to whatever the failure was.
My iMac's drive issue had nothing to do with the water on the case, so they did the repairs.
I would assume/expect that a decent and honest Apple Store would treat an open iMac the same way.