Buddhist mythology is not consistent when the texts draw from different sources. Both yaksas and raksasas come from vedic mythology and have a different background: the yaksa was originally a ‘miraculous being’ (in the singular), appearing already in the Rgveda. In the Atharvaveda the Yaksa came to mean something like the impersonal cosmic absolute, like Brahman. This continues in the Brahmanas.
Only in the Grhyasutras - which represent much more popular elements than the more elitist previous literature - they got demonic elements, comparable to the later view on Gandharvas and Raksasas. This continues in the Sanskrit epics. So the demonic Yakkhas in the suttas draw from the late popular mythology while the positive ones goes back to the older view.
Raksasas on the other hand were always demonic forces, starting in the late Samhitas but mostly of the Brahmanas, trying to interrupt the Devas from performing rituals, and opposed to the Brahmins who perform the rituals as well. Accordingly Agni is usually the god who keeps them in check. They are occasionally also possessing beings and as far as I remember are also shapeshifters, which echoes the later Buddhist mythology of Mara.
Anyhow, eventually as a late development you can lump them together as demonic demigods, they just come from different mythological backgrounds.