You can do it in pure XPath, but if you want to wrap it in a function that should work fine too:
declare function local:returnValueForKey(
$key as xs:string,
$plist as element(plist)
) as element(dict)?
{
$plist//key[. = $key]/following-sibling::*[1]/self::dict
};
local:returnValueForKey('secondDictionary', <plist>...</plist>)
=>
<dict>
<key>subDictionary</key>
<dict>
<key>aBoolValue</key>
<false/>
</dict>
</dict>