How to display node details and call function in *.html.twig
I think I would have implemented this feature differently. Let me just answer the specific question, and then I will tell you an alternative approach.

Custom 'functions' in Twig

The easiest thing for you could be to Implement a twig macro.

However, macros could be limiting. To have all the PHP power you can create a twig extension function

If you are in a rush and are into bad practices, then there is the twig tweak php filter, so that you can do this:

&lt;div class="bad-practice"&gt;
     {{ 'return _get_node_details();'|php }} 
&lt;/div&gt;


Alternative implementation using Drupal views


Create a Drupal View, with a Block Display.
Place the new Block, using the Block Layout.
If you need to do a heavy alteration use a hook_views_data_alter().