If your scratch org is configured with a namespace, then the assumption seems to be that this org is for package development, and any customisations (including fields from unmanaged packages) are automatically prefixed with the namespace. Generally if you're in an org with a namespace, everything gets that namespace.
Code in a managed package does not need to use the namespace to refer to other packaged components (fields, classes, objects etc.) and this means you can develop that same code inside of other dev orgs etc. too where the namespace isn't present. I recommend never using the namespace for the current package in Apex for this exact reason.
If you're using a scratch org and install another managed package that you depend on (for instance, we use a base package with our schema then other stuff on top) then you do need to use the namespace to reference components of that pacakge, and those will show locally with the namespace.
Sidenote on Packages and Client Orgs
This may or may not be relevant to you, but it's related to this question. If a client org (i.e. org where your managed package is installed) contains a field with the same API name as a field in your package on the same object, your code can never access the field that exists natively in the org. Even using dynamic SOQL/Apex, if you reference Field__c
in your code then the namespace will always be added under the hood, so you'll only ever be able to access NS__Field__c
and never Field__c
. I had to learn this one the hard way.