It sounds primitive and un-artistic, but yes, sheer amount of material counts for a lot in these things. Writing a dozen variations on an existing theme certain amounts to a new composition by most people's standards, while writing only an arrangement of the theme is clearly a mere arrangement. More interesting are cases where someone takes a known theme and writes only one piece or movement about it.
A fugue "on a theme by XY" is usually considered a separate composition, since it is much longer than the theme and considerable ingenuity goes into figuring out how the theme can be interleaved with itself, what counterpoints to choose etc.
Writing a sonata movement on someone else's main theme would be a borderline case, since so much in the sonata form is determined by the nature of the main theme. (That's probably why this is almost never done.)
A "Fantasia on the theme X" has much more freedom in what to do with the theme. It's possible to write a very derivative movement that barely merits the name "composition", but also to write an ingenious, intricate one that clearly leaves the theme far behind. Again, how much material is added and what counts for a lot there.
(Please note that there is also a huge range of artistic effort between different kinds of arrangements. Mozart's "arrangement" of fugues by Bach for string quartet consists largely in transcribing the four voices into different clefs - he didn't even add fingerings, bowings, dynamics or anything like that. They are considered prominent today only because of the magical name of Mozart. On the other hand, orchestrating an ambitious piano piece, particular one that is already almost orchestral in texture like the Pictures at an exhibition, offers huge scope for ingenious contribution by the arranger.)