For a Label
you can create a custom theme and alter the font_color_shadow
property.
The effect looks like this:


To create a custom theme, scroll down to "Theme" in the label's inspector. Click to add a new theme. A new panel will open at the bottom of the screen. Click "Edit theme.." > "Create Empty Template". A new panel will open in the inspector. From here you can set the theme settings for all the elements that use themes.
I notice, however, that the theme settings for RichTextLabel
don't include this property. This might be related to why you were unable to set it via code.
If you don't find a satisfying method for adding this border in Godot, you can always use a font that has this border built in by design. For example, here are some fonts with outlines built in.