I’ll give you a couple cases 1 & 2 for your cases A & B.
Case 1: If wordpress is installed at site.com/blog/ and you are using permalinks, then a request to site.com/blog/my-post-title/ will in case A look for your image at the address site.com/wp-images/masthead2.jpg while in case B it will interpret the address of the image as site.com/blog/my-post-title/wp-images/masthead2.jpg
Case 2: You are not using permalinks, but with the address above being the installation (site.com/blog/) you request the page site.com/blog/?p=23 and in case A the image will be expected in site.com/wp-images/masthead2.jpg while in case B it will interpret the address of the image as site.com/blog/wp-images/masthead2.jpg
However, if you are using this code as a css rule in a css file, the path will be relative to the css file where it’s called, be it in site.com/blog/wp-content/themes/mytheme/style.css or whatever. If your image is in site.com/blog/wp-content/wp-images/masthead2.jpg you could just use url(../../wp-images/masthead2.jpg); or url(/blog/wp-content/wp-images/masthead2.jpg);