This is possible with native query parameters like this:
$posts = get_posts([
'post__in' => [2,5,3,1,4,6],
'orderby => 'post__in',
]);
This combination will instruct WP to fetch specific posts by ID and order them in the specific way that you supplied IDs.