Basically it works like this: When you draw with a brush on a transparent part of a layer the brush behaves as if it would draw on an opaque layer instead and the opaque color used is what is set as the brush’s background color. So when you would draw a semi transparent line over a transparent part of the canvas the foreground and the background color would mix as if it would draw on a opaque layer instead.
Krita has a fore- and background color that can be set for the brush (and other tools) but I couldn’t find a way to emulate this behavior. I think I first saw it in PaintShop Pro, many years ago when it still existed. Maybe it’s already in Krita, and I just didn’t find it in the pixel brush engine. Otherwise I would write a feature request for it when people think it’s a useful feature to have.