I see what you are saying about st.components.v1.html creating iframes and st.markdown('''...''', unsafe_allow_html=True) not working as desired with <script>...</script>.
I am not aware of any straightforward way to add scripts to <head>. The two above mentioned methods are the only entry points that I have learned about so far. When I stick a simple script definition in with the components API, it ran for me, but if it’s not workable in your use case, I’m afraid I don’t have a fundamentally different direction to go. There’s another discussion thread on injecting javascript here, but it’s just a discussion about the components API and creating a custom component if a simple script embedding isn’t enough, so not sure if there’s any new information there to glean. Sorry I can’t be more help.