.Format says scratchpad variable isn't a string even though it is

I’m observing some weird behaviour right now while executing the snippet:

{{/* Somewhere else */}}
{{ .Scratch.Set "dateFormat" "Jan 2, 2006" }}

{{ $date := .Lastmod.Format (.Scratch.Get "dateFormat") }}

This is the given error:

ERROR 2020/05/05 05:39:04 Failed to render pages: render of "home" failed: execute of template  
 failed: template: index.html:7:11: executing "main" at <partial $widget_path .>: error calling partial:   
execute of template failed: template: partials/widgets/pages.html:63:7: executing "partials/widgets  
/pages.html" at <partial "li_compact" .>: error calling partial: execute of template failed: template:   
partials/li_compact.html:34:6: executing "partials/li_compact.html" at <partial "page_metadata" .>:  
 error calling partial: "/home/utkarsh/Website/themes/materialistic/layouts/partials  
/page_metadata.html:15:40": execute of template failed: template:   
partials/page_metadata.html:15:40: executing "partials/page_metadata.html" at <"dateFormat">:   
invalid value; expected string

Explicitly using string function worked for me but I don’t see why it should be required in the first place since I assigned a string to scratchpad initially.