Alright, I have performed a simple test to check if the UDF is able to detect a possible cycle of about 100000 elements, and it does! The test does these steps:
Insert pairs (1, 2), (2, 3), all the way up to (99999, 100000) with basic INSERT INTO operations. These were very fast at first, but slowed down as the database grew bigger
Try to insert (100000, 1). This operation failed with the expected error
I suppose WITH's recursion depth is not limited, unlike TRIGGERs', which is limited by the SQLITE_MAX_TRIGGER_DEPTH definition? In any case, this was merely a test to ensure WITH would not cause any problems for being used in a UDF inside a TRIGGER, and my actual use case should not need that many rows.
Thank you!