The integration of 6G technologies into Non-Terrestrial Networks (NTNs) presents significant challenges, particularly due to the limited onboard capacities of space-based platforms and their dynamic nature. By leveraging the virtualized 6G O-RAN paradigm, satellites can operate 6G software stacks on Software-Defined Radios (SDRs) based on General Purpose Processors (GPPs), facilitating on-demand connectivity tailored to application needs. However, optimizing the placement of network functions in such distributed environments becomes complex, requiring advanced approaches to dynamically manage the limited available resources. This paper explores the use of artificial intelligence for Virtual Network Function (VNF) allocation optimization within a 6G-NTN testing platform that leverages an O-RAN-based distributed architecture, orchestrated on top of Kubernetes. To achieve this, the optimization problem is formalized and a comprehensive framework is developed for dynamic and complex NTN environments. The proposed approach is validated through a test campaign aimed at characterizing the 6G-NTN platform in terms of virtual resource utilization, focusing on key service-oriented performance indicators such as latency. Subsequently, machine learning algorithms are applied to optimize VNF allocation, primarily to minimize service latency and improve overall network responsiveness within the 6G-NTN platform. This work highlights the significant role of machine learning in dynamically orchestrating network resources, setting the stage for future advancements in 6G network architectures.