This is an older question, but here’s the answer for future generations:
WordPress will check the styles against a list of allowed properties and it will still strip the style attribute if none of the styles are safe. The default allow list is:
text-alignmargincolorfloatborderbackgroundbackground-colorborder-bottomborder-bottom-colorborder-bottom-styleborder-bottom-widthborder-collapseborder-colorborder-leftborder-left-colorborder-left-styleborder-left-widthborder-rightborder-right-colorborder-right-styleborder-right-widthborder-spacingborder-styleborder-topborder-top-colorborder-top-styleborder-top-widthborder-widthcaption-sideclearcursordirectionfontfont-familyfont-sizefont-stylefont-variantfont-weightheightletter-spacingline-heightmargin-bottommargin-leftmargin-rightmargin-topoverflowpaddingpadding-bottompadding-leftpadding-rightpadding-toptext-decorationtext-indentvertical-alignwidth
This list is, as with most things in WordPress, filtered! You can add display to it as follows to let your code work as expected:
add_filter( 'safe_style_css', function( $styles ) {
$styles[] = 'display';
return $styles;
} );