Any idea why this logic isn't working?

From the documentation of Android Developer Platform:

Since padding is used to offset content for shadows, you cannot set padding on CardView. Instead, you can use content padding attributes in XML or setContentPadding(int, int, int, int) in code to set the padding between the edges of the CardView and children of CardView.

Before Lollipop, CardView adds padding to its content and draws shadows to that area. This padding amount is equal to maxCardElevation + (1 - cos45) * cornerRadius on the sides and maxCardElevation * 1.5 + (1 - cos45) * cornerRadius on top and bottom.

As u can see you don’t have the possibility to manipulate maxCardElevation parameter.

It’s probably hard to answer the question, because in kodular we don’t have full acces to every possible parameter of classes. It seems like cardview View makes some background calculations for the border and shadows and depending on the android version it works differently. Maybe that’s the reason. For example this:
https://developer.android.com/reference/androidx/cardview/widget/CardView#setPreventCornerOverlap(boolean)

2 Likes